javascript - Invoking Main Controller function from Modal Controller - AngularJS -
problem summary
want invoke getcost function present in main controller, modal controller.
pseudo-code explain problem follows.
i am opening modal dialog follows:
.... //i want invoke getcost function modal controller //so pass via 'resolve' $scope.getcost = function() { return i*x+y;//calculates , returns cost } $modal.open({ templateurl: '/html/mymodal.html', controller: mymodalctrl, resolve: { getcostnow: function () { return $scope.getcost; } } }); .....
and in mymodalctrl like:
var mymodalctrl = function($scope, $modalinstance, $http, getcostnow) { function updateorder() { //trying invoke getcost function reference here //but not work. var thecurrentcostis = getcostnow(); } }
try (notice scope:$scope):
$modal.open({ templateurl: '/html/mymodal.html', controller: mymodalctrl, scope:$scope, resolve: { getcostnow: function () { return $scope.getcost; } } });
you can use event listeners, send event:
$scope.$emit(name, args);
and in parent listen event:
$scope.$on('eventname', function(event, data) { console.log(data); });
Comments
Post a Comment