JPS
JPS

Reputation: 2760

AngularJS: $modal, passing $scope variable to child controller

JS Code,

var mod= $modal.open({
    animation: true, 
    templateUrl: $scope.url,
    controller: function($scope, $modalInstance,custObj) {
        alert(custObj); /*************Line 1**************************/
        $scope.save = function() {
            $modalInstance.close();
        };

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

    },
    resolve : {
        /************Resolving current scope value to retrieve it in Line 1*******/
        custObj: $scope.customer;
    }
}); 

Though I sent $scope.customer object via resolve property, the modal controller is not getting the value. Am I missing anything?

Upvotes: 0

Views: 555

Answers (2)

Gustav
Gustav

Reputation: 3576

The value of custObj in the resolve-object should be a function returning what you want to inject:

resolve: {
  custObj: function(){
        return $scope.customer;
     }
}

check documentation for $routeProvider resolve

Upvotes: 1

atinder
atinder

Reputation: 2090

use

locals : {
   custObj: $scope.customer;
}

instead of resolve.

Upvotes: 0

Related Questions