简体   繁体   English

将简单的参数传递给有角度的ui-bootstrap模态?

[英]pass simple parameter to angular ui-bootstrap modal?

I see many posts about posting many complicated things to ui-bootstrap modals, but I just want to pass a simple parameter so that I might use it to display different content in the dialog. 我看到许多关于将许多复杂的东西发布到ui-bootstrap模态的文章,但是我只想传递一个简单的参数,以便可以使用它在对话框中显示不同的内容。

For example, I have the main document which has MyDocumentController as mydoc 例如,我有将MyDocumentController as mydoc的主文档

In MyDocumentController is a function such as MyDocumentController是一个诸如

_this.modals = {
    inviteUser: function() {
      $modal.open({
        animation: true,
        templateUrl: 'modules/templates/modals/modal-invite-user.html',
        controller: 'UserInviteModalController as invite',
        size: 'lg'
      });
    }, ...

And I call it in the main document like so, here is where I want to pass the param from: 我在主文档中这样称呼它,这是我要从中传递参数的地方:

<a href="" ng-click="users.modals.inviteUser(returningUser)">

And here is the controller for the modal: 这是模态的控制器:

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

    });
})();

What is the process for passing the simple param to the dialog's controller? 将简单参数传递给对话框的控制器的过程是什么?

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

And then inject it into your controller: 然后将其注入到控制器中:

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

    _this.someVar = returningUser;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM