我只想在函数返回真值时显示特定的 div...为什么它在这里不起作用?
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();
}
});
这是div
<div id="loader" ng-controller="LoaderController as loaderCtrl" ng-if="loaderCtrl.getIsLoading()"></div>
最佳答案
您不能在调用 Controller 的同一个 html 指令中使用 ng-if。想一想—— Controller 需要存在,以便 Angular 调用该方法。
将 ng-if 下移一层或将 ng-controller 上移一层,它应该可以工作。
关于javascript - ng-if 在函数上无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46854690/