AngularJS - How to Create a Modal Dialog from the Controller

anad2312

I am able to create a Modal Dialog from within the html file, but I need to click a button, do some logic in the controller (i.e. service call and validate data), and based off of the response, I need to popup a modal dialog from within the controller in order to inform the user that there is an error.

I have figured out how to do it from within the html file, but it will not popup from within the controller. Here are snippets of what I have:

login.html - Contains a form with a submit button (I am not pasting the entire file):

  <form name="loginPage" class="form-signin" role="form" style="position: absolute; margin: 250px 0px 0px 500px;" ng-submit="submitForm(userForm.$valid)">
<h2 class="form-signin-heading">Login</h2>
<input type="text" class="form-control" ng-model="name" placeholder="Username" required autofocus>
<input type="password" class="form-control" ng-model="password" ng-click="password" placeholder="Password" required>
<label class="checkbox">
    <input type="checkbox" value="remember-me"> Remember me
</label>
<input type="submit" class="btn btn-lg btn-primary btn-block" value="Log In"/>

controllers.js - Contains this code (I am not pasting the entire file):

 $scope.submitForm = function () {
      //Making an Ajax service call (SOAP service call being made) in this function, and then results will then call a function named ajaxFinish

 $.ajax({
        url: productServiceUrl,
        type: "POST",
        dataType: "xml",
        data: soapMessage,
        processData: false,
        success: function (xml) {
            ajaxFinish($scope, xml);
        },
        contentType: "text/xml; charset=utf-8"
    });

}

  function ajaxFinish($scope, xml) {
      var modalInstance = $modal.open({
        templateUrl: 'view/myModalContent.html',
        controller: ModalInstanceCtrl,
        resolve: {
            items: function () {
                return $scope.items;
            }
        }
    });
 }

myModalContent.html -

 <label>Alert Message!</label>

When I debug, it hits the ajaxFinish method, but nothing opens up. I am using stateProvider. I have a file called modules.js that contains a bunch of pages, one of which is the modal dialog:

modules.js (A snippet of some of the code) -

         .state('main.myModalContent', {
            url: '',
            controller: ModalDemoCtrl,
            templateUrl: 'view/myModalContent.html'
        })

When I try the Plunker in the comments below, my modal dialog pops up on the left of the screen... completely cut off. See screenshot: enter image description here

Farhan Khan

Glad you got it sorted out. If anyone else runs into issues, use the plunker as reference. If the modal shows up, but is off screen, check your css. You've probably overridden bootstrap css modal classes. There's good documentation on angular-ui website, as well as the github page.

REFERENCES

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: How to access main controller from modal controller and directive controller

From Dev

AngularJS modal dialog form object is undefined in controller

From Dev

AngularJS open modal from controller

From Dev

Displaying a bootstrap Modal dialog from Angular Controller

From Dev

returning data from angularjs modal dialog service

From Dev

How to get json data into AngularJS modal dialog?

From Dev

Opening a modal from within another controller in AngularJS

From Dev

Displaying a Modal Dialog in AngularJS

From Dev

Displaying a Modal Dialog in AngularJS

From Dev

AngularJS directive to modal dialog

From Dev

How to deal with modal controller outside AngularJs module?

From Dev

Prevent AngularJS modal from closing based on logic inside the modal controller

From Dev

Prevent AngularJS modal from closing based on logic inside the modal controller

From Dev

on bootstrap modal dialog load get data from controller

From Dev

on bootstrap modal dialog load get data from controller

From Dev

How to show a modal dialog from a modeless form?

From Dev

AngularJS how to create a reusable template for Bootstrap modal

From Dev

AngularJs Modal Dialog on part of the page

From Dev

how to create a non-modal bootstrap dialog box

From Dev

How to create black transparent overlay/ modal dialog with centered text on an image

From Dev

how to open modal from angular controller

From Dev

How to submit the modal to the controller and refresh the ajax after the modal dialog for edit closes

From Dev

How to submit the modal to the controller and refresh the ajax after the modal dialog for edit closes

From Dev

How to Forward $scope from Controller to Controller AngularJS?

From Dev

Angularjs - watch modal window close from another controller

From Dev

How to move modal dialog

From Dev

how to open and set controller Mobile-Angular modal from controller

From Java

How to create separate AngularJS controller files?

From Dev

How to close bootstrap modal window from angularjs

Related Related

  1. 1

    Angularjs: How to access main controller from modal controller and directive controller

  2. 2

    AngularJS modal dialog form object is undefined in controller

  3. 3

    AngularJS open modal from controller

  4. 4

    Displaying a bootstrap Modal dialog from Angular Controller

  5. 5

    returning data from angularjs modal dialog service

  6. 6

    How to get json data into AngularJS modal dialog?

  7. 7

    Opening a modal from within another controller in AngularJS

  8. 8

    Displaying a Modal Dialog in AngularJS

  9. 9

    Displaying a Modal Dialog in AngularJS

  10. 10

    AngularJS directive to modal dialog

  11. 11

    How to deal with modal controller outside AngularJs module?

  12. 12

    Prevent AngularJS modal from closing based on logic inside the modal controller

  13. 13

    Prevent AngularJS modal from closing based on logic inside the modal controller

  14. 14

    on bootstrap modal dialog load get data from controller

  15. 15

    on bootstrap modal dialog load get data from controller

  16. 16

    How to show a modal dialog from a modeless form?

  17. 17

    AngularJS how to create a reusable template for Bootstrap modal

  18. 18

    AngularJs Modal Dialog on part of the page

  19. 19

    how to create a non-modal bootstrap dialog box

  20. 20

    How to create black transparent overlay/ modal dialog with centered text on an image

  21. 21

    how to open modal from angular controller

  22. 22

    How to submit the modal to the controller and refresh the ajax after the modal dialog for edit closes

  23. 23

    How to submit the modal to the controller and refresh the ajax after the modal dialog for edit closes

  24. 24

    How to Forward $scope from Controller to Controller AngularJS?

  25. 25

    Angularjs - watch modal window close from another controller

  26. 26

    How to move modal dialog

  27. 27

    how to open and set controller Mobile-Angular modal from controller

  28. 28

    How to create separate AngularJS controller files?

  29. 29

    How to close bootstrap modal window from angularjs

HotTag

Archive