AngularJS nested directives depth -
i searching way mark depth of nested directives. lets have item-container , ch-item , nest them couple of times this:
<ch-item-container> <ch-item> <ch-item></ch-item> <ch-item-container> <ch-item> end of tree </ch-item> </ch-item-container> </ch-item> </ch-item-container> is there way mark depth without attaching ?
<ch-item depth="0"></ch-item> i prepared plunker example : http://plnkr.co/edit/zc0xcewjttroax99qc6i?p=preview
is maybe possible pass variable "down" elements ?
one solution count number of $parent iterations every scope: gives depth of scope relatively $rootscope.
here implementation: http://plnkr.co/edit/jdfqb1knfa7odhmfvhri?p=preview
with shared service being:
chitemmodule.service('depth', function () { return function depth(scope, d) { d = d || 0; if (!scope.$parent) { return d; } return depth(scope.$parent, d + 1); } });
Comments
Post a Comment