Sunday, 15 February 2015

angularjs - Accessing parent's parent controllers through Angular require attribute -



angularjs - Accessing parent's parent controllers through Angular require attribute -

in below example, accordion-group directive shares controller , scope parent accordion, using "require: '^accordion'" attribute within accordion-group directive.

if wanted create kid directive, under accordion-group, how access accordion controller well? requiring ^accordion , ^accordiongroup not seem work.

https://github.com/angular-ui/bootstrap/blob/master/src/accordion/accordion.js

it work way. beingness stupid. fiddle posterity here.

'use strict'; angular.module('myapp', []).controller('onecontroller', function() { this.test = function(element) { element.css('color', 'red'); } }).directive('one', function() { homecoming { restrict: 'e', transclude: true, replace: true, controller: 'onecontroller', template: '<span ng-transclude>and </span>', } }).directive('two', function() { homecoming { restrict: 'e', transclude: true, replace: true, require: '^one', template: '<span ng-transclude>and </span>', } }).directive('three', function() { homecoming { restrict: 'e', transclude: true, replace: true, require: '^one', template: '<span ng-transclude>and 1 two</span>', link: function(scope, element, attrs, ctrl) { ctrl.test(element); } } });

angularjs angularjs-directive

No comments:

Post a Comment