bambi
bambi

Reputation: 1179

Model binding not working in Angular UI Bootstrap modal

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);
        }

});

Upvotes: 1

Views: 2371

Answers (1)

Iliya Reyzis
Iliya Reyzis

Reputation: 3677

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

Upvotes: 2

Related Questions