gpt4 book ai didi

javascript - 将简单参数传递给 Angular ui-bootstrap 模式?

转载 作者:行者123 更新时间:2023-11-30 16:51:56 25 4
gpt4 key购买 nike

我看到很多关于将许多复杂的东西发布到 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)">

这是模态的 Controller :

    (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();
}
};

});
})();

将简单参数传递给对话框 Controller 的过程是怎样的?

最佳答案

尝试使用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;
}
}
});
}, ...

然后将它注入(inject)到你的 Controller 中:

angular.module('mymodule')
.controller('UserInviteModalController', function($log, $modalInstance, toastr, returningUser) {
var _this = this;

_this.someVar = returningUser;

关于javascript - 将简单参数传递给 Angular ui-bootstrap 模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30400016/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com