Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular ng-if throwing TypeError: Cannot read property '0' of null

Tags:

angularjs

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>
like image 924
Kallan Avatar asked Dec 05 '22 22:12

Kallan


1 Answers

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>
like image 161
Omri Aharon Avatar answered Dec 29 '22 12:12

Omri Aharon