[英]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.