Javascript AngularJS-ReferenceError:“;someScopeVar“;没有定义
我正在用AngularJS构建一个反馈表单,其中用户数据存储在Javascript AngularJS-ReferenceError:“;someScopeVar“;没有定义,javascript,angularjs,Javascript,Angularjs,我正在用AngularJS构建一个反馈表单,其中用户数据存储在$scope.feedback中。现在我想包括一个进度条,需要确定百分比 // $scope-variable to hold the data. $scope.feedback = { title : undefined, name : undefined, email : undefined, tel : undefined }; /
$scope.feedback
中。现在我想包括一个进度条,需要确定百分比
// $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
的属性总数。
要计算用户已填充的属性数量,有一个函数determinatePercentageOfattributesDefined
,每当触摸输入字段时都会调用该函数
问题是,未定义变量$scope.percentageOfAttributesDefined
,并且在浏览器控制台中出现以下错误:
ReferenceError: percentageOfAttributesDefined is not defined
我还尝试在控制器的其他地方创建变量,但得到了相同的错误。有人知道原因吗?
可以毫无问题地访问其他范围变量,如$Scope.feedback
感谢您抽出时间:)console.log($scope.percentageOfAttributesDefined)代码>
这应该可以解决您的问题。您可以使用console.log($scope.percentageOfAttributesDefined)检查一下吗代码>@GirdhariAgrawal似乎就是这样。唯一的问题是日志不起作用,因为我忘记了$scope。。。谢谢你能接受我的回答吗?