我想用AngularJS和Bootstrap
這是我的代碼
HTMLAngularJS +引導dismissable警報
<div class="col-lg-9" ng-controller="manageProfile">
<form style="margin-top:80px">
<div class="alert alert-success alert-dismissible" ng-controller="dismiss" ng-show="successAlert == true">
<button type="button" class="close" data-dismiss="alert" aria-label="Close" ng-click="dismissSuccess()">
<span aria-hidden="true">×</span>
</button>
Username Changed!
</div>
<div class="form-group">
<label>Display Name</label>
<input type="text" ng-model="currentName" class="form-control" placeholder="Display Name">
</div>
<button class="btn btn-md" ng-click="changeName()">Change Username!</button>
</form>
</div>
AngularJS
profile.controller('manageProfile', ['$scope', function($scope) {
$scope.changeName = function() {
var user = Parse.User.current();
user.setUsername($scope.currentName);
user.save(null, {
success: function(user) {
$scope.successAlert = true;
$scope.$apply();
},
error: function(error) {
$scope.errorAlert = true;
$scope.$apply();
}
});
};
}]);
profile.controller('dismiss', ['$scope', function($scope) {
$scope.dismissSuccess = function(){
$scope.successAlert = false;
$scope.$apply();
}
$scope.dismissError = function(){
$scope.errorAlert = false;
}
}]);
的概念是要創造一個dismissable警報在我通過點擊Change Username
按鈕更改了我的用戶名後,它會顯示將$scope.successAlert
的值設置爲true
,並顯示不可用的引導警報。之後,如果我關閉了警報,它將觸發dismissSuccess()
並將值$scope.successAlert
設置爲false
,這樣如果我再次更改我的用戶名(不重新加載頁面),它將再次顯示警報。
但是,此代碼不會讓我得到的結果我想