我目前正在使用Angular.JS开发一个小应用程序
在我看来,我有以下按钮
editUser方法看起来像这样:
$scope.editUser = function (user,$event) {
$scope.userToEdit = user;
$mdDialog.show({
controller: DialogController,targetEvent: $event,templateUrl: '/js/modules/user/views/edit.tmpl.html',parent: angular.element(document.body),clickOutsideToClose: true,scope: $scope
})
.
then(function (answer) {
if (answer == "save") {
for (right in $scope.allSystemRightsStatements) {
if ($scope.allSystemRightsStatements[right].selected) {
if( $scope.userToEdit.rights==null){
$scope.userToEdit.rights = [];
}
$scope.userToEdit.rights.push($scope.allSystemRightsStatements[right]);
}
}
$scope.updateUser($scope.userToEdit);
}
$scope.userToEdit = {};
},function () {
$scope.userToEdit = {};
});
};
$scope.updateUser = function (user) {
//userService.updateUser makes a $http PUT request
var promise = userService.updateUser(user);
promise.then(function (result) {
$mdToast.show(
$mdToast.simple(result.message)
.position($scope.getToastPosition())
.hideDelay(3000)
);
},function (reason) {
$mdToast.show(
$mdToast.simple(reason)
.position($scope.getToastPosition())
.hideDelay(3000)
);
},function (update) {
});
};
现在,对话框很好地显示,并且还调用了答案功能,一切都按预期进行.
但是,当我第二次单击该按钮时,不会执行editUser功能.好像在关闭对话框中删除了按钮中的onClick事件.
非常感谢任何帮助解决这个问题,
谢谢
最佳答案
如here所述
it is probably a good idea to explicitly mention that the scope will be destroyed upon hiding the dialog (so people shouldn’t pass a controller’s $scope directly).
(关于你传递给mdDialog的范围)
因此,当范围被破坏时,angular不会将您的按钮与任何操作绑定