当模态是开放的/活动的时候,如何为模态内容设置新的值?
这是示例代码。
angular.module('plunker', ['ui.bootstrap']);
var ModalDemoCtrl = function ($scope, $modal, $log, $timeout) {
$scope.test = "test variable"
var modalInstance = $modal.open({
templateUrl: 'myModalContent.html',
controller: ModalInstanceCtrl,
resolve: {
test: function () {
return $scope.test;
}
}
});
$timeout( function(){
$scope.test = "Hello World!";
}, 5000 );
};
var ModalInstanceCtrl = function ($scope, $modalInstance, test) {
$scope.test = test;
$scope.$watch('test',function (newValue, oldValue) {
$scope.test = test;
});
};在父控制器中,我用“测试变量”插入模态1,超时后(5秒),我希望模态变量更改为"Hello“,而不关闭模态。
可以测试这里
发布于 2017-10-05 07:59:49
您可以直接将控制器作用域绑定到类似于
var modalInstance = $modal.open({
templateUrl: 'myModalContent.html',
controller: ModalInstanceCtrl,
scope: $scope
});这是工作柱塞
发布于 2017-10-05 13:02:27
在$timeout中使用ModaInstanceCtrl函数,然后相应地更改变量的作用域值。下面是示例代码:
angular.module('plunker', ['ui.bootstrap']);
var ModalDemoCtrl = function ($scope, $modal, $log) {
$scope.test = "test variable"
var modalInstance = $modal.open({
templateUrl: 'myModalContent.html',
controller: ModalInstanceCtrl,
scope: $scope,
resolve: {
test: function () {
return $scope.test;
}
}
});
};
var ModalInstanceCtrl = function ($scope, $modalInstance, $timeout, test) {
$timeout(function(){
$scope.test = "variable"
}, 2000);
};http://plnkr.co/edit/f1zhkWH6aEtZDoKv8egO?p=preview
https://stackoverflow.com/questions/46580561
复制相似问题