I am trying to show and hide html using ng-if . When the $scope.isTokenValid is false, it works fine.But when $scope.isTokenValid is true I am getting below error. Please help
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;
})
});
View
<div class="row" ng-if="isTokenValid()">
<h1>Valid</h1>
</div>
<div class="row" ng-if="!isTokenValid()">
<h1>InValid</h1>
</div>
You're using isTokenValid
like a function when it is in fact a property, change it to:
<div class="row" ng-if="isTokenValid">
<h1>Valid</h1>
</div>
<div class="row" ng-if="!isTokenValid">
<h1>InValid</h1>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With