将简单参数传递给 angular ui-bootstrap 模态?
pass simple parameter to angular ui-bootstrap modal?
我看到很多关于将许多复杂的东西发布到 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();
}
};
});
})();
将简单参数传递给对话框控制器的过程是什么?
尝试使用 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;
我看到很多关于将许多复杂的东西发布到 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();
}
};
});
})();
将简单参数传递给对话框控制器的过程是什么?
尝试使用 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;