ngModel
单击Cancel
按钮 ( sweet alert
) 以切换选项卡(div
在html
代码中)后,我试图更改该值,但它不起作用。
这是HTML:
<div ng-show="tabsMainMenu=='tabOne'">
<h1>tabOne</h1>
</div>
<div ng-show="tabsMainMenu=='tabTwo'">
<h1>tabTwo</h1>
</div>
和JS:
swal({
title: 'Cancel?',
text: 'Are you sure?',
icon: 'warning',
buttons: true
})
.then((cancel) => {
if (cancel) {
// Go back to Tab One
$scope.tabsMainMenu = 'tabOne';
}
});
只有当我把mouse cursor
在Cancel
按钮上的html
网页是认识的新值tabsMainMenu
ngModel
。
有任何想法吗?
Promises 通常是异步的,所以它们在 angular 的生命周期之外。这意味着当您的.then
函数运行时,angular 不知道任何更改。因此,您只需要将.then
函数中的内容包装在$scope.apply
.
https://docs.angularjs.org/api/ng/type/$rootScope.Scope#$apply
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句