Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I got the plunkr working. I'm not sure if its exactly what you're looking for. I copied the main code changes below.</p> <p>Here's the plunkr:</p> <p><a href="http://plnkr.co/edit/GEiGBIMywkjWAaDMKFNq?p=preview" rel="nofollow">http://plnkr.co/edit/GEiGBIMywkjWAaDMKFNq?p=preview</a></p> <p>The modified directive looks like this now:</p> <pre><code>app.directive('list', function() { return { restrict: 'A', scope: { items: '=', ctrlFn: '&amp;' //this function is defined on controller }, templateUrl: 'list.html', transclude: true, link: function(scope, element, attrs, controller) { //directive fn that calls controller defined function scope.dirFn = function(param) { if(scope.ctrlFn &amp;&amp; typeof scope.ctrlFn == 'function') { //make sure its a defined function scope.ctrlFn( {'name': param} ); //not sure why param has to be passed this way } } } }; }); </code></pre> <p>And here's how it's called in the html file that's bound to your controller: </p> <pre><code>&lt;div list items="supsNames" ctrl-fn="myAlert(name)"&gt; &lt;a ng-click="dirFn(item.name)"&gt;{{item.name}}&lt;/a&gt; &lt;/div&gt; </code></pre> <p>I think what was happening before is that you were trying to use a function defined in your controller within the isolated scope of the directive, so it wasn't working--that function was undefined in the directive. So what I did was added another parameter to the directive that accepts method binding (I think that's what its called) with the '&amp;'. </p> <p>So basically you pass your controller method to the directive, and that method gets invoked however you want by the directive defined method I creatively named "dirFn". I don't know if this is the best way per se, but I've used it in an existing project with good results ;)</p>
    singulars
    1. This table or related slice is empty.
    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.
    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