Spacemancraig
Spacemancraig

Reputation: 1396

Passing value to modal scope in angular ui-bootstrap

I have a form setup in angular and am using ui-bootstrap for a modal dialog that appears before submission is complete. My site is setup in Sharepoint and uses a context to determine if they are on English or Spanish version of the site and display the proper language content. I want to pass the bool value IsInEnglish to the modal to display the correct <div> but I am not finding a solution to pass this value to the scope of the modal.

        $scope.continue = function () { //this is off an ng-click on a button

        var modalInstance = $modal.open({
            templateUrl: '_layouts/Applications/VolunteerApp/modal/myModal.html',
            controller: 'vAppController'
        });

        modalInstance.opened.then(function () {
            $scope.modalIsInEnglish = IsInEnglish;

        });
    };

Upvotes: 0

Views: 887

Answers (1)

The Head Rush
The Head Rush

Reputation: 3357

Add a resolve to $modal's instantiation object:

    var modalInstance = $modal.open({
        templateUrl: '_layouts/Applications/VolunteerApp/modal/myModal.html',
        controller: 'vAppController',
        resolve: {
          myVar: function() {
            return someVal;
          }
        }
    });

and then pass someVal as an argument of the function that invokes the modal:

 $scope.continue = function (someVal)

To access someVal in the modal controller, pass it in as an argument for the modal controller:

function myModalController($scope, someVal) { // do stuff }

Upvotes: 3

Related Questions