0

Problem Summary
I want to invoke getCost function present in main controller, from modal controller.
Pseudo-Code for this to explain the problem follows.

I am am opening modal dialog as follows:

....
//I want to invoke this getCost function from the Modal Controller
//So i pass it via 'resolve'
      $scope.getCost = function() {
            return i*x+y;//calculates and returns some cost
       }

        $modal.open({
             templateUrl: '/html/MyModal.html',
             controller: MyModalCtrl,
             resolve: {
            getCostNow: function () {
                return $scope.getCost;
             }
         }
        });
.....

And in MyModalCtrl this is like:

var MyModalCtrl = function($scope, $modalInstance, $http, getCostNow) {


 function updateOrder()
  {
     //Trying to invoke getCost function reference here
     //But this does not work.
     var theCurrentCostIs = getCostNow();
  }
}

1 Answer 1

1

Try this (notice the scope:$scope):

$modal.open({
    templateUrl: '/html/MyModal.html',
    controller: MyModalCtrl,     
    scope:$scope,
    resolve: {
        getCostNow: function () {
           return $scope.getCost;
        }
    }
});

You can then use event listeners, to send an event:

$scope.$emit(name, args);

And in the parent listen for the event:

$scope.$on('eventName', function(event, data) { console.log(data); });
Sign up to request clarification or add additional context in comments.

Comments

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.