Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/475.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript AngularJS-ReferenceError:“;someScopeVar“;没有定义_Javascript_Angularjs - Fatal编程技术网

Javascript AngularJS-ReferenceError:“;someScopeVar“;没有定义

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 }; /

我正在用AngularJS构建一个反馈表单,其中用户数据存储在
$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。。。谢谢你能接受我的回答吗?