[英]Refresh Angular-ui bootstrap $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";
}
在我的modal.html模板中,我有:
<div ng-click="checkError()">Check Error</div>
<div ng-show="errorMessage">{{ errorMessage }}</div>
<div ng-click="errorMessage = false">Close</div>
$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字符串。
您是否嘗試過以下方法:
$scope.checkError = function() {
$scope.errorMessage = "another error";
$scope.$apply();
}
也許$摘要不會被觸發。
編輯:問題不是關於$摘要,而是關於不同的范圍被修改。 創建模態時,Angular會為其分配子$ scope,因此單擊此按鈕時:
<div ng-click="errorMessage = false">Close</div>
在模態范圍內創建一個新的“errorMessage”變量。 因此,即使父作用域中的errorMessage變量有更新,模式也會在其作用域中優先使用errorMessage。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.