ng,如果工作不正常

ng-if not working properly?

本文关键字:不正常 工作 如果 ng      更新时间:2024-01-17

当我调用console.log($scope.showAddEvent)时,它显示showAddEvent正在更改,但ng-if似乎没有反映这些更改。它根本没有显示出来。

我对angularjs还很陌生,所以我不确定我做错了什么。。。

html

  <ion-footer-bar align-title="center" class="bar-positive" ng-if="$scope.showAddEvent == true">
      <div class="title" ng-click="modal.show()">Add Event</div>
  </ion-footer-bar>

controller.js

  $scope.showAddEvent;
  var currentUser = Backand.getUserDetails().$$state.value;
  if (currentUser.role == "Admin" || currentUser.role == "Verified"){
      $scope.showAddEvent = true;
      console.log(currentUser.role);
      console.log('you can add event');
      console.log($scope.showAddEvent);
  }
  else {
      $scope.showAddEvent = false;
      console.log(currentUser.role);
      console.log('You cannot add Event');
    console.log($scope.showAddEvent);
  }

在您的模板中,您不应该引用scope。更改

<ion-footer-bar align-title="center" class="bar-positive" ng-if="$scope.showAddEvent == true">

<ion-footer-bar align-title="center" class="bar-positive" ng-if="showAddEvent">