1

I have simple example using Angular UI Bootstrap modal service. In this example I don't understand why model binding is not working. Instead of seeing "Doing something..." on modal dialog I see "{{message}}". What I need to change?

Example is here: http://plnkr.co/edit/fJhS3e7At11tJTuNSWAB?p=preview

modal html looks like this:

<div ng-app="myModule">
    <div ng-controller="modalInstanceController" class="modal-body">
        <div>{{message}}</div>
    </div>
</div>

And definition of module and controllers:

var myAppModule = angular.module('myModule', ['ui.bootstrap']);

myAppModule.controller('modalInstanceController', function ($scope, $modalInstance, message) {
    var vm = this;
    vm.message = message;
});

myAppModule.controller('myController', function ($scope, $modal) {


        $scope.open = function open() {

            var modalInstance = $modal.open({
                templateUrl: 'modal.html',
                backdrop: 'static',
                //windowClass: 'custom-modal-wait',
                dialogFade: false,
                keyboard: false,
                controller: 'modalInstanceController',
                resolve: {
                    message: function () {
                        return "Doing something ...";
                    }
                }
            });

            setTimeout(function(){
                modalInstance.close('close');
                },5000);
        }

});

1 Answer 1

2

to use the value you pass to the modal, you need to put it on its scope, so set the modal controller as so:

myAppModule.controller('modalInstanceController', function ($scope, $modalInstance, message) {
    $scope.message = message;
});

and remove the ng-controller from modal.html, you are already assigning him a controller when you create the modal instance

ng-controller="modalInstanceController"

your fixed example : http://plnkr.co/edit/vnfL72EBMXsQ1NzlJNEF?p=preview

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks. Is is possible to somehow declare message on this object in modalInstanceController?
Sure. You mean to pass an object to the Modal? look at this plnkr, is that what you mean? plnkr.co/edit/AISzGdRdr24Ai4ROcnFh?p=preview
What I wanted is this: plnkr.co/edit/fJhS3e7At11tJTuNSWAB?p=preview But anyway, your answer was true.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.