0

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?

3
  • 2
    Shouldn't the value of custObj in the resolve-object be a function that returns your $scope.customer? Reading the documentation for $routeProvider's resolve I believe that's how it's supposed to be Commented Aug 14, 2015 at 8:13
  • @Gustav, Thanks for the point. I thought without a function I can directly pass the values. After changing it to a function everything works fine. Commented Aug 14, 2015 at 8:17
  • I'll post as answer as well Commented Aug 14, 2015 at 8:18

2 Answers 2

1

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

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

Comments

0

use

locals : {
   custObj: $scope.customer;
}

instead of resolve.

1 Comment

Any specific reason why we can choose locals instead of resolve?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.