user3770093
user3770093

Reputation: 345

Angular JS Passing $scope to Modal

http://jsfiddle.net/dwmkerr/8MVLJ/

I'm trying to experiment from the sample above. My problem is that the modal cannot seem to read anything from the $scope that called it.

Javascript

$scope.sampleTest = "SAMPLE TEXT"; // additional code
$scope.show = function() {

    ModalService.showModal({
        templateUrl: 'modal.html',
        controller: "ModalController"
    }).then(function(modal) {
        modal.element.modal();
        modal.close.then(function(result) {
            $scope.message = "You said " + result;
        });
    });
};

HTML

<p>It's your call...{{sampleText}}</p>

The modal only shows "It's your call..." instead of "It's your call... SAMPLE TEXT"

Is there anything I'm missing out here?

Upvotes: 0

Views: 4672

Answers (1)

link
link

Reputation: 2510

Since the modal has its own controller (which is separate from the controller that called the modal), you would need to pass any variables you need into the resolve function of the modal.

Then in the modal controller, you would need to add the resolved object to the scope so it is able to be bound in the modal's view

Hope this helps.

Upvotes: 2

Related Questions