javascript - Retrieving child directive scope from parent through element.find -


i can't use "require" because have directive can have many different parents cannot predict be. need in each parent able retrieve controller or scope of child directive , invoque method disable button. have plunker shows problem.

https://plnkr.co/edit/od1mjzoq1ep54pj6k6ti?p=preview

  .directive('parent', function($compile, $rootscope) { return {   restrict: 'e',   scope: {},   templateurl: 'parent.html',   link: postlinkfunction };  function postlinkfunction(scope, element, attributes) {   var directive = element.find('child');   var directivescope = directive.isolatescope();    console.log(directivescope); } }) .directive('anotherparent', function() { return {   restrict: 'e',   scope: {},   templateurl: 'parent.html',   link: postlinkfunction };  function postlinkfunction(scope, element, attributes) {   var directive = element.find('child');   var directivescope = directive.isolatescope();    console.log(directivescope); } }) .directive('child', function() { return {   restrict: 'e',   scope: {},   controller: function($scope, $element) {     var vm = this;      $scope.isdisabled = false;      $scope.disablemenu = function () {       $scope.isdisabled = true;     };      $scope.number = 1;   },   templateurl: 'child.html' }; }); 

the isolatescope empty if have populated it, child directive has have isolate scope can't share scope parent, , said can't use require. in theory element.find way hacky easy implement can't make work. appreciated, in advance!.

your parent module should comunicate childs through variables in isolated scope this:

app.directive("testdir", function() {    var directive = {     restrict: "a",     template: "<div><input value='testbutton' type='button' data-ng-disabled='isdisabled'></div>",     scope:      {       isdisabled: "=isdisabled"     }   };    return directive; }); 

here's working demo


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -