Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could define a directive that would <em>proxy</em> another directive like so</p> <pre><code>&lt;div proxy="'ng-if'" proxy-value="'foo'"&gt;&lt;/div&gt; &lt;div ng-init="n='ng-if'; v='foo';" proxy="n" proxy-value="v"&gt;&lt;/div&gt; </code></pre> <p>that would both be equivalent to</p> <pre><code>&lt;div ng-if="foo"&gt;&lt;/div&gt; </code></pre> <p>the <code>proxy</code> directive definition would be</p> <pre><code>app.directive('proxy', function ($parse, $injector) { return function (scope, element, attrs) { var nameGetter = $parse(attrs.proxy); var name = nameGetter(scope); var value = undefined; if (attrs.proxyValue) { var valueGetter = $parse(attrs.proxyValue); value = valueGetter(scope); } var directive = $injector.get(name + 'Directive')[0]; if (value !== undefined) { attrs[name] = value; } return directive.compile(element, attrs, null)(scope, element, attrs); }; }); </code></pre> <p>This is actually kind of a fun directive to write once in a life. :-) but it lacks a lot of the native directive features (for instance <em>template</em>, <em>templateUrl</em>, <em>controller</em>, etc). All those features are available in the original Angular source code in a private function called <code>applyDirectivesToNode</code>, so it is easy to copy/paste some parts, but ugly... I have written a demo matching your usecase <a href="http://jsfiddle.net/tutGZ/2/" rel="nofollow">here</a>.</p> <p>Another solution, if you don't mind your proxied directive does not share the same element as the <code>proxy</code> directive's one, would be to <code>$compile</code> a dynamic template at runtime that you would include. Here is a <a href="http://jsfiddle.net/2MW39/1/" rel="nofollow">demo</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload