AngularJS Bootstrap Modal $modalInstance.dismiss is not a function

Ryan Munsch

When I click the cancel button on my modal, the $modalInstance.dismiss function binded with ng-click on my modal template isn't working.

The console has been throwing the error: "$modalInstance.dismiss is not a function"

MODAL TEMPLATE:

<div class="my-modal ng-scope" id="my-modal">
  <div class="modal-header">
    <h3 class="modal-title" id="modal-title">Create a new room</h3>
  </div>
<div class="modal-body" id="modal-body">
  <form>
    Enter a room name<br>
    <input type="text" name="new-room-name">
  </form>
  <div class="modal-footer">
    <button class="btn btn-warning" type="button" ng-click="modal.cancel()">Cancel</button>
    <button class="btn btn-primary" type="button" ng-click="modal.save()">Create Room</button>
  </div>
</div>

MAIN CONTROLLER:

(function() {
  function HomeCtrl(Room, $scope, $uibModal, $log, $document) {
var home = this;

home.chatRooms = Room.all;
//TO TEST ADD METHOD FROM ROOM.JS
// this.addRoom = Room.add();

home.open = function () {
  modalInstance = $uibModal.open({
    animation: true,
    backdrop: true,
    templateUrl: '../templates/modal.html',
    controller: 'ModalInstanceCtrl',
    controllerAs: 'modal',
    bindToContoller: true,
    scope: $scope,
    size: 'lg',
    resolve: {
      '$modalInstance': function () { return function () { return modalInstance; } }
    }
  });


console.log(modalInstance);

modalInstance.result.then(function (newChatRoom) {
  home.selected = newChatRoom;
  console.log(newChatRoom);
}, function () {
  $log.info('Modal dismissed at: ' + new Date());
});
  };
}

  angular
    .module('blocChat')
    controller('HomeCtrl', ['Room', '$scope', '$uibModal', '$log', '$document', HomeCtrl]);
})();

MODAL CONTROLLER:

(function() {
  function ModalInstanceCtrl(Room, $scope, $modalInstance, $log, $document) {
var modal = this;

this.save = function() {
  $modalInstance.close(newChatRoom);
};

this.cancel = function() {
  $modalInstance.dismiss('cancel');
};

  }

  angular
    .module('blocChat')
    .controller('ModalInstanceCtrl', ['Room', '$scope', '$modalInstance', '$log', '$document', ModalInstanceCtrl]);
})();

I've spent about 3 hours messing around with my code, looking at the AngularJS Bootstrap UI documentation, several StackOverflow threads, and other sites and have gotten no where. Any help would be appreciated.

Nikolaj Dam Larsen

In the version of angular ui bootstrap you're using, the reference to the modal instance is called $uibModalInstance. So try changing your controller to this:

(function() {
  function ModalInstanceCtrl(Room, $scope, $uibModalInstance, $log, $document) 
  {
    var modal = this;

    this.save = function() {
      $uibModalInstance.close(newChatRoom);
    };

    this.cancel = function() {
      $uibModalInstance.dismiss('cancel');
    };
  }

  angular
    .module('blocChat')
    .controller('ModalInstanceCtrl', ['Room', '$scope', '$uibModalInstance', '$log', '$document', ModalInstanceCtrl]);
})();

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

angularjs - $modalInstance.dismiss action redirects page to modal's templateUrl

From Dev

AngularJS Modal (ui.bootstrap.modal) unable to trigger jQuery event after modal is opened (modalInstance.opened)

From Dev

AngularJS Modal (ui.bootstrap.modal) unable to trigger jQuery event after modal is opened (modalInstance.opened)

From Dev

Data-Dismiss: How to dismiss bootstrap modal inside function

From Dev

Data-Dismiss: How to dismiss bootstrap modal inside function

From Dev

angularjs - Accessing ui-bootstrap modal dismiss and close function from another controller

From Dev

Call function defined in modal on ui-bootstrap modal dismiss

From Dev

Unknown provider: $modalInstanceProvider <- $modalInstance in Angularjs modal

From Dev

Bootstrap Modal validation displaying on dismiss

From Dev

Bootstrap Modal validation displaying on dismiss

From Dev

bootstrap dismiss modal and display another modal

From Dev

Angularjs Dismiss Modal Outside Modal Controller

From Dev

access scope of modalInstance returned by ui-bootstrap $modal.open()

From Dev

AngularJS UI Bootstrap dismiss() won´t work

From Dev

Bootstrap modal and AngularJS

From Dev

Call function after modal loads angularjs ui bootstrap

From Dev

Calling AngularJS function from a remote page loaded by Bootstrap modal

From Dev

Simplest way to dismiss Bootstrap alerts when the containing modal is dismissed

From Dev

How to dismiss a web modal dialog from bootstrap manually?

From Dev

Can't dismiss custom UI Bootstrap modal by backdrop click

From Dev

Bootstrap modal data-dismiss button is posting the form

From Java

Bootstrap modal: is not a function

From Dev

Bootstrap : TypeError: $(...).modal is not a function

From Dev

AngularJS reusable modal bootstrap directive

From Dev

AngularJS Bootstrap alert dismiss-on-timeout attribute doesn't work

From Dev

AngularJS UI.Bootstrap Alert text not displaying and dismiss button not responding

From Dev

dismiss modal ViewControllers

From Dev

Dismiss modal segue

From Dev

Dismiss modal on Apple Watch

Related Related

  1. 1

    angularjs - $modalInstance.dismiss action redirects page to modal's templateUrl

  2. 2

    AngularJS Modal (ui.bootstrap.modal) unable to trigger jQuery event after modal is opened (modalInstance.opened)

  3. 3

    AngularJS Modal (ui.bootstrap.modal) unable to trigger jQuery event after modal is opened (modalInstance.opened)

  4. 4

    Data-Dismiss: How to dismiss bootstrap modal inside function

  5. 5

    Data-Dismiss: How to dismiss bootstrap modal inside function

  6. 6

    angularjs - Accessing ui-bootstrap modal dismiss and close function from another controller

  7. 7

    Call function defined in modal on ui-bootstrap modal dismiss

  8. 8

    Unknown provider: $modalInstanceProvider <- $modalInstance in Angularjs modal

  9. 9

    Bootstrap Modal validation displaying on dismiss

  10. 10

    Bootstrap Modal validation displaying on dismiss

  11. 11

    bootstrap dismiss modal and display another modal

  12. 12

    Angularjs Dismiss Modal Outside Modal Controller

  13. 13

    access scope of modalInstance returned by ui-bootstrap $modal.open()

  14. 14

    AngularJS UI Bootstrap dismiss() won´t work

  15. 15

    Bootstrap modal and AngularJS

  16. 16

    Call function after modal loads angularjs ui bootstrap

  17. 17

    Calling AngularJS function from a remote page loaded by Bootstrap modal

  18. 18

    Simplest way to dismiss Bootstrap alerts when the containing modal is dismissed

  19. 19

    How to dismiss a web modal dialog from bootstrap manually?

  20. 20

    Can't dismiss custom UI Bootstrap modal by backdrop click

  21. 21

    Bootstrap modal data-dismiss button is posting the form

  22. 22

    Bootstrap modal: is not a function

  23. 23

    Bootstrap : TypeError: $(...).modal is not a function

  24. 24

    AngularJS reusable modal bootstrap directive

  25. 25

    AngularJS Bootstrap alert dismiss-on-timeout attribute doesn't work

  26. 26

    AngularJS UI.Bootstrap Alert text not displaying and dismiss button not responding

  27. 27

    dismiss modal ViewControllers

  28. 28

    Dismiss modal segue

  29. 29

    Dismiss modal on Apple Watch

HotTag

Archive