javascript - ng-if 在函数上无法正常工作

标签 javascript angularjs

我只想在函数返回真值时显示特定的 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/

相关文章:

javascript - 使用标签上的 jQuery .mouseenter 突出显示段落中的单词?

javascript - 用两种不同的方式编写函数 : one way results in a TypeError and the other does not. 为什么?

angularjs - 我应该如何在 Angular Material 中实现多重选择选项?

angularjs - Heroku 推送问题 : Bower resolver not found

angularjs - 404 使用 UI-Bootstrap 和 Plunker

html - Angularjs:单个 html 中的多个部分?

javascript - 使用原始文件部署 Angular-App

javascript - 包含带有phonegap的指令

javascript - 根据ajax拉入的值更改html单元格边框

javascript - 如何使用requestJS的get方法设置cookie?