ユーザーデータが$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
などの変数に問題なくアクセスできます。時間を割いて
感謝:)
あなたは 'console.log($ scope.percentageOfAttributesDefined);' –
@GirdhariAgrawalでそれを確認してください。唯一の問題は、$スコープを忘れてログが機能しなかったことです。 ...ありがとうございます –
私の答えを受け入れることができますか? –