Alessandro Pierro
Alessandro Pierro

Reputation: 11

ng-if doesn't work properly on a function

I want to show a specific div only while a function return true value... why isn't it working here ?

var app = angular.module('. . .');

app.controller('LoaderController', function($scope, $http,communication) {

  var loader = this;
  var isLoading = false;

  $scope.Loading = false;

  this.getIsLoading = function(){
    return true; // return communication.getIsLoading();
  }


});

This is the div

<div id="loader" ng-controller="LoaderController as loaderCtrl" ng-if="loaderCtrl.getIsLoading()"></div>

Upvotes: 0

Views: 404

Answers (1)

thomasmost
thomasmost

Reputation: 1070

You can't use ng-if in the same html directive that invokes the controller. Think about it -- the controller needs to exist for angular to call that method on it.

Move ng-if down a level or the move the ng-controller up one and it should work.

Upvotes: 3

Related Questions