当我调用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);
}
最佳答案
在模板中,您不应引用范围。更改
<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">