有没有人知道动态使用ngshow根据ajax返回值显示/隐藏内容的方法?
这是我到目前为止所做的:
$scope.loggedShow = false;
var user = '';
$scope.login = function(username, password) {
$http({
url: 'ajax/login.php',
method: 'POST',
data: {
'username': username,
'password': password
}
}).success(function(data, status, headers, config) {
console.log(data);
console.log('working');
user = 'logged';
if (user == 'logged') {
$scope.loggedShow = true;
} else {
$scope.loggedShow = false;
}
getBanners();
}).error(function(data, status, headers, config) {
console.log('womp womp');
});
};
这是html:
<div class="widget-header header-color-blue" ng-show="loggedShow" >
<div class="row">
<div class="col-sm-6">
<h4 class="bigger lighter">
<i class="glyphicon glyphicon-align-justify"></i>
BANNERS
</h4>
</div>
<div class="col-sm-3">
<button restrict access="admin" ng-click="addNewClicked=!addNewClicked;"
class="btn btn-sm btn-danger header-elements-margin">
<i class="glyphicon glyphicon-plus"></i>
NEW PROJECT
</button>
</div>
<div class="col-sm-3">
<input type="text" ng-model="filterBanners"
class="form-control search header-elements-margin"
placeholder="FILTER BANNERS">
</div>
</div>
</div>
基本上,我将控制器中的值设置为false,然后当返回值进入时,我验证它并将其设置为true,这应该显示该元素。不幸的是,这不符合预期。它处理原始语句很好(它正确地隐藏了元素),但是在返回值时,范围不会更新。角度是如何工作的吗?我应该使用指令吗?