Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>With <em>replace:true</em> the replacement process migrates all of the attributes / classes from the old element (<em>&lt;my-button ...></em>) to the new one (the root element in the template, <em>&lt;li ...></em> ). Transclude moves the content of the old element to the specified (ng-transclude) element. I'm not sure if there's a simple way to change which element in the template that will receive the migrated attributes.</p> <p>To achieve what you want you could probably do some dom manipulation in a custom compile function in the my-button directive. However, I think it'd be a better idea to create a new isolate scope in the my-button directive:</p> <pre class="lang-xml prettyprint-override"><code>&lt;my-buttons&gt; &lt;my-button click-fn="doOneThing()"&gt;abc&lt;/my-button&gt; &lt;my-button click-fn="doAnotherThing()"&gt;def&lt;/my-button&gt; &lt;/my-buttons&gt; </code></pre> <p>(notice I've changed ng-click to click-fn)</p> <pre class="lang-js prettyprint-override"><code>module.directive('myButtons', function () { return { restrict:'E', transclude:true, replace:true, template:'&lt;ul class="u" ng-transclude&gt;&lt;/ul&gt;' } }); module.directive('myButton', function () { return { scope:{clickFn:'&amp;'}, restrict:'E', transclude:true, replace:true, template:'&lt;li class="l"&gt;&lt;button ng-click="clickFn()" ng-transclude&gt;&lt;/button&gt;&lt;/li&gt;' } }); </code></pre> <p>I've also made a <a href="http://jsfiddle.net/UWEsN/">working version of your fiddle</a>.</p> <p>To understand how the isolate scope works (<em>scope:{clickFn:'&amp;'}</em>) I recommend you read the <a href="http://docs.angularjs.org/guide/directive">angular guide on directives</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