我有使用Angular UI Bootstrap模式服务的简单示例。在这个例子中,我不明白为什么模型绑定不起作用。而不是看到"做某事......"在模态对话框中,我看到" {{message}}"。我需要改变什么?
示例在这里: http://plnkr.co/edit/fJhS3e7At11tJTuNSWAB?p=preview
modal html看起来像这样:
<div ng-app="myModule">
<div ng-controller="modalInstanceController" class="modal-body">
<div>{{message}}</div>
</div>
</div>
模块和控制器的定义:
var myAppModule = angular.module('myModule', ['ui.bootstrap']);
myAppModule.controller('modalInstanceController', function ($scope, $modalInstance, message) {
var vm = this;
vm.message = message;
});
myAppModule.controller('myController', function ($scope, $modal) {
$scope.open = function open() {
var modalInstance = $modal.open({
templateUrl: 'modal.html',
backdrop: 'static',
//windowClass: 'custom-modal-wait',
dialogFade: false,
keyboard: false,
controller: 'modalInstanceController',
resolve: {
message: function () {
return "Doing something ...";
}
}
});
setTimeout(function(){
modalInstance.close('close');
},5000);
}
});
答案 0 :(得分:2)
要使用传递给模态的值,需要将其放在其范围内,因此将模态控制器设置为:
myAppModule.controller('modalInstanceController', function ($scope, $modalInstance, message) {
$scope.message = message;
});
并从modal.html中删除ng-controller
,您在创建模态实例时已经为他分配了一个控制器
ng-controller="modalInstanceController"