javascript - Can the controller of a modal window access functions in parent controller -


suppose launch modal window using $modal.open within angular directive.

does modal window have access functions defined parent directive?

directive controller code

.. function parentfunction() {      return 5; }  $scope.showdialog = function() {      var dialog = $modal.open({      controller: 'modalcontroller',      ... } 

'modalcontroller' code

var val = parentfunction();

it won't have lexical scope access, there 2 ways (that know of) "pass data" controller, depending on makes more sense you:

1) via $scope:

$scope.parentfn = function parentfn(){ };  var dialog = $modal.open({      controller: 'modalcontroller',      scope: $scope,      //... }); 

2) via resolve:

function parentfn(){ }  var dialog = $modal.open({      controller: 'modalcontroller',      resolve: {        parentfn: function(){          return parentfn;        }      },      // ... }); 

then parentfn local injectable modalcontroller:

.controller("modalcontroller", function(parentfn){    parentfn(); }); 

or...

if defined controller inline, have lexical scope access:

function parentfn(){ }  var dialog = $modal.open({      controller: function modalcontroller(){         parentfn();      },      // ... }); 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -