Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In your directive add the changePage call there (I know it's not where you want it). Have it call the parents scope changePage with the same parameter.</p> <pre><code>$scope.changePage = function(index){ console.log("running changePage"); $scope.$parent.changePage(index); //might want to check if the parent scope has this too } </code></pre> <p>As another tip, in directives you shouldn't use the $ in front of the variables being sent in. In this case that would be $scope, $element, $attrs. The $ you see in front of scope in controllers (not linking functions) is there to let you know that it is being injected. It is not being injected in the linking controller. For instance, here:</p> <pre><code>app.directive("pager", function ($injector1, $injector2) { </code></pre> <p>This is where injected parameters would go, and you want to be able to distinguish the two of them. I realize this got a little off track and I hope the suggestion I have for the changePage is what you're looking for.</p> <p><strong>Edit</strong>: Updated fiddle <a href="http://jsfiddle.net/dVFDT/48/" rel="nofollow">http://jsfiddle.net/dVFDT/48/</a></p> <p><strong>Modified answer for future searchers</strong>: The function you were passing in via the click method like so:</p> <pre><code>..... click="changePage()"..... </code></pre> <p>Needed to be changed to:</p> <pre><code>..... click="changePage"..... </code></pre> <p>This means you're passing the function through and not the function call. This meant that in your directive when you wired up the changePage callback you were calling the function with the index like this:</p> <pre><code>changePage()(1) </code></pre> <p>and that's why you were getting undefined.</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.
 

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