2016-08-31 21 views
1

ユーザーデータが$scope.feedbackに格納されているAngularJSでフィードバックフォームを作成しています。今度は進捗バーを追加し、割合を決定する必要があります。AngularJS - ReferenceError: "someScopeVar"が定義されていません

// $scope-variable to hold the data. 
    $scope.feedback = { 
     title : undefined, 
     name : undefined, 
     email : undefined, 
     tel : undefined 
    }; 

    // Get the total amount of attributes of $scope.feedback 
    var totalAmountOfAttributesOfFeedback = 0; 
    for (var k in $scope.feedback) { 
     if ($scope.feedback.hasOwnProperty(k)) { 
      ++totalAmountOfAttributesOfFeedback; 
     } 
    } 

    // Get the amount of defined attributes of $scope.feedback 
    // to determine the percentage of Progress 
    $scope.determinePercentageOfAttributesDefined = function() { 
     var amountOfDefinedAttributesOfFeedback = 0; 
     for (var l in $scope.feedback) { 
      if (angular.isDefined($scope.feedback[l])) { 
       ++amountOfDefinedAttributesOfFeedback; 
      } 
     } 
     $scope.percentageOfAttributesDefined = (amountOfDefinedAttributesOfFeedback/totalAmountOfAttributesOfFeedback)*100; 
     console.log(percentageOfAttributesDefined); 
    }; 

パーセントを計算するには、属性の合計量を$scope.feedbackと数えます。 ユーザーがすでに入力した属性の数をカウントするには、関数determinePercentageOfAttributesDefinedがあります。これは、入力フィールドに触れるたびに呼び出されます。

問題は変数$scope.percentageOfAttributesDefinedが定義されていないこと、と私は、ブラウザのコンソールで次のエラーを取得する:私も私のコントローラにどこかの変数を作成しようとした

ReferenceError: percentageOfAttributesDefined is not defined 

が、同じエラーを取得。誰かがその理由を知っていますか? 他のスコープ - $scope.feedbackなどの変数に問題なくアクセスできます。時間を割いて

感謝:)

+0

あなたは 'console.log($ scope.percentageOfAttributesDefined);' –

+0

@GirdhariAgrawalでそれを確認してください。唯一の問題は、$スコープを忘れてログが機能しなかったことです。 ...ありがとうございます –

+0

私の答えを受け入れることができますか? –

答えて

2

console.log($scope.percentageOfAttributesDefined);

これはあなたの問題を解決する必要があります。

関連する問題