ng-如果不能正常工作?

时间:2016-04-05 15:11:45

标签: javascript angularjs

当我致电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);
  }

1 个答案:

答案 0 :(得分:3)

在模板中,您不应该引用范围。变化

<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">