1

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.

For example, I have the main document which has MyDocumentController as mydoc

In MyDocumentController is a function such as

_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?

1 Answer 1

2

Try using 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;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.