所以我要说:
$scope.errorMessage = "error1";
$scope.addCardModal = $modal.open({
animation: true,
templateUrl: 'pages/templates/modals/modal.html',
size: "lg",
scope: $scope
});
$scope.checkError = function() {
$scope.errorMessage = "another error";
}
在我的 modal.html 模板中我有:
<div ng-click="checkError()">Check Error</div>
<div ng-show="errorMessage">{{ errorMessage }}</div>
<div ng-click="errorMessage = false">Close</div>
- 当我加载我的模态时,错误消息按预期显示。
- 当我点击关闭时,错误消息会像预期的那样隐藏。
- 但是,当我单击Check Error 时,
$scope
会发生变化,但不会转换回模态。
有谁知道为什么会发生这种情况以及如何让 $scope
回到模态?因为如果我关闭模式,然后重新打开它,则会再次显示正确的错误消息。
最佳答案
试试这个:
$scope.errorMessage = "error1";
$scope.addCardModal = $modal.open({
animation: true,
templateUrl: 'pages/templates/modals/modal.html',
size: "lg",
scope: $scope
});
$scope.checkError = function() {
$scope.errorMessage = "another error";
}
$scope.toggleError = function(){
$scope.errorMessage = "";
}
HTML:
<div ng-click="checkError()">Check Error</div>
<div ng-show="errorMessage">{{ errorMessage }}</div>
<div ng-click="toggleError()">Close</div>
我添加了一个 toggleError() 函数,这样您就可以清空 errorMessage 字符串。
关于javascript - 刷新 Angular-ui bootstrap $scope,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30631263/