我正在尝试使用 ng-if 显示和隐藏 html。当 $scope.isTokenValid 为假时,它工作正常。但是当 $scope.isTokenValid 为真时,我得到以下错误。请帮忙
TypeError: Cannot read property '0' of null
at $parseFunctionCall (angular.js:12346)
at Object.expressionInputWatch (angular.js:12754)
at Scope.$get.Scope.$digest (angular.js:14235)
at Scope.$get.Scope.$apply (angular.js:14506)
at done (angular.js:9659)
at completeRequest (angular.js:9849)
at XMLHttpRequest.requestLoaded (angular.js:9790)
Controller
angular.module('clientApp')
.controller('RegCtrl', function($scope, $routeParams, $http) {
var url = "http://localhost:3000/signup/" + $routeParams.invitation_token;
$http.get(url)
.success(function(response) {
$scope.isTokenValid = response.isValid;
})
});
看法
<div class="row" ng-if="isTokenValid()">
<h1>Valid</h1>
</div>
<div class="row" ng-if="!isTokenValid()">
<h1>InValid</h1>
</div>
最佳答案
当 isTokenValid
实际上是一个属性时,您将其用作函数,请将其更改为:
<div class="row" ng-if="isTokenValid">
<h1>Valid</h1>
</div>
<div class="row" ng-if="!isTokenValid">
<h1>InValid</h1>
</div>
关于angularjs - Angular ng-if 抛出 TypeError : Cannot read property '0' of null,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28901552/