Displaying a bootstrap Modal dialog from Angular Controller

SNV7

I'm trying to figure out how I can present a bootstrap modal dialog from my Angular controller. Basically what I have is a table. When the user clicks on a table row I want to present a modal dialog that contains details about the selected row.

The way I'm thinking about approaching this is have each table row respond to an ng-click. The ng-click will call a function in the controller and this function will present the modal dialog as well as pass it the data it needs to display.

I know how to display a modal dialog from the view itself, but I'm not sure how I can trigger the modal from the controller. Any ideas?

The controller, for the view, has the following function which will be called when the user selects a row to view a modal dialog.

$scope.rowClicked = function(rowID){
    $scope.dataForModal = Data.get(rowID, function(err,data){
        //Here is where I'd like to display the modal dialog in the view
    });
}
jvdveuten

See http://angular-ui.github.io/bootstrap/#/modal

Use a ng-click="showDetails(item)" on the cell/row in your view. Then use this code in your controller to show the Modal:

$scope.showDetails = function (item) {
    var modalInstance = $modal.open({
        templateUrl: 'yourview.html',
        controller: 'DetailModalController',                       
        resolve: {
            item: function () {
                return  item;
            },                            
        }
    });

    modalInstance.result.then(function (item) {
        // ok
    }, function () {
        // dismiss
    });
};

Your modal controller can be something like this:

angular.module('app').controller('DetailModalController', [
    '$scope', '$modalInstance', 'item',
    function ($scope, $modalInstance, item) {

        $scope.item = item;

        $scope.dismiss = function () {
            $modalInstance.dismiss();
        };

        $scope.close = function () {                    
             $modalInstance.close($scope.item);                       
        };
    };
}]);

With $modalInstance.close($scope.item); you can pass an object. With $modalInstance.dismiss(); you dismiss the modal without an object.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Accessing angular bootstrap modal form from controller

From Dev

Close angular bootstrap modal window from a controller

From Dev

Close angular bootstrap modal window from a controller

From Dev

Calling a bootstrap modal from an Angular 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

Twitter Bootstrap 3 modal dialog not displaying

From Dev

bootstrap-angular modal dialog: can not return value from select

From Dev

Testing Bootstrap modal in Angular controller

From Dev

Angular bootstrap modal controller scope

From Dev

Bootstrap Modal with Angular pulling from a controller containing an image array

From Dev

Angular populate Bootstrap modal form from controller data

From Dev

Angular populate Bootstrap modal form from controller data

From Dev

Bootstrap Modal with Angular pulling from a controller containing an image array

From Dev

Change class of an element with a radio button in a modal (Angular UI-Bootstrap: Retrieving values from a modal dialog window)

From Dev

Displaying a Modal Dialog in AngularJS

From Dev

Displaying modal login dialog

From Dev

Displaying a Modal Dialog in AngularJS

From Dev

AngularJS - How to Create a Modal Dialog from the Controller

From Dev

Bootstrap modal dialog set attributes from javascript

From Dev

Angular - UI Bootstrap Datepicker not displaying over Bootstrap Modal

From Dev

Angular - UI Bootstrap Datepicker not displaying over Bootstrap Modal

From Dev

How to call ui bootstrap modal popup controller from within angular js another controller

From Dev

Using Angular Bootstrap Modal with external controller

From Dev

Angular Bootstrap UI modal in controller or directive?

From Dev

How to switch from a bootstrap modal to a angular modal

From Dev

How to switch from a bootstrap modal to a angular modal

From Dev

MVC 5 - raise Bootstrap Modal from Controller

From Dev

Angular object from controller not displaying in html

Related Related

  1. 1

    Accessing angular bootstrap modal form from controller

  2. 2

    Close angular bootstrap modal window from a controller

  3. 3

    Close angular bootstrap modal window from a controller

  4. 4

    Calling a bootstrap modal from an Angular Controller

  5. 5

    on bootstrap modal dialog load get data from controller

  6. 6

    on bootstrap modal dialog load get data from controller

  7. 7

    Twitter Bootstrap 3 modal dialog not displaying

  8. 8

    bootstrap-angular modal dialog: can not return value from select

  9. 9

    Testing Bootstrap modal in Angular controller

  10. 10

    Angular bootstrap modal controller scope

  11. 11

    Bootstrap Modal with Angular pulling from a controller containing an image array

  12. 12

    Angular populate Bootstrap modal form from controller data

  13. 13

    Angular populate Bootstrap modal form from controller data

  14. 14

    Bootstrap Modal with Angular pulling from a controller containing an image array

  15. 15

    Change class of an element with a radio button in a modal (Angular UI-Bootstrap: Retrieving values from a modal dialog window)

  16. 16

    Displaying a Modal Dialog in AngularJS

  17. 17

    Displaying modal login dialog

  18. 18

    Displaying a Modal Dialog in AngularJS

  19. 19

    AngularJS - How to Create a Modal Dialog from the Controller

  20. 20

    Bootstrap modal dialog set attributes from javascript

  21. 21

    Angular - UI Bootstrap Datepicker not displaying over Bootstrap Modal

  22. 22

    Angular - UI Bootstrap Datepicker not displaying over Bootstrap Modal

  23. 23

    How to call ui bootstrap modal popup controller from within angular js another controller

  24. 24

    Using Angular Bootstrap Modal with external controller

  25. 25

    Angular Bootstrap UI modal in controller or directive?

  26. 26

    How to switch from a bootstrap modal to a angular modal

  27. 27

    How to switch from a bootstrap modal to a angular modal

  28. 28

    MVC 5 - raise Bootstrap Modal from Controller

  29. 29

    Angular object from controller not displaying in html

HotTag

Archive