我看到很多关于向ui-bootstrap模式发布许多复杂内容的帖子,但我只是想传递一个简单的参数,以便我可以用它在对话框中显示不同的内容。
例如,我的主文档有MyDocumentController as mydoc
在MyDocumentController
中是一个函数,例如
_this.modals = {
inviteUser: function() {
$modal.open({
animation: true,
templateUrl: 'modules/templates/modals/modal-invite-user.html',
controller: 'UserInviteModalController as invite',
size: 'lg'
});
}, ...
我在主文档中这样称呼它,这里是我想传递参数的地方:
<a href="" ng-click="users.modals.inviteUser(returningUser)">
这是模态的控制器:
(function() {
'use strict';
angular.module('mymodule')
.controller('UserInviteModalController', function($log, $modalInstance, toastr) {
var _this = this;
_this.someVar = HERE'S WHERE I WANT TO GET THE VALUE returningUser FROM THE NG-CLICK
_this.inviteDialog = {
close: function() {
$modalInstance.close();
},
resendInvite: function() {
toastr.success('A new invite has been sent.');
$modalInstance.close();
}
};
});
})();
将简单参数传递给对话框控制器的过程是什么?
答案 0 :(得分:2)
尝试使用resolve
:
_this.modals = {
inviteUser: function(returningUser) {
$modal.open({
animation: true,
templateUrl: 'modules/templates/modals/modal-invite-user.html',
controller: 'UserInviteModalController as invite',
size: 'lg',
resolve: {
returningUser: function() {
return returningUser;
}
}
});
}, ...
然后将其注入您的控制器:
angular.module('mymodule')
.controller('UserInviteModalController', function($log, $modalInstance, toastr, returningUser) {
var _this = this;
_this.someVar = returningUser;