Note that there are some explanatory texts on larger screens.

plurals
  1. PO$watch on two-way binding in directive not invoked
    text
    copied!<p>I am trying to create a simple paginator directive. The idea is that i have a dynamic table based on a category. Eg: Category-> Fruits, table will have Apple, Bananas, Oranges etc Category -> Vegetables, table will have Spinach, Cauliflower and so on</p> <p>I am trying to build a dynamic paginator directive</p> <p>The code is below</p> <pre><code>myApp.directive("myPaginator",function(){ return { restrict:"AE", replace:true, scope:{ displayPage :"=", numPages : "=" }, link:function(scope, element, attrs, ctrl){ scope.$watch(scope.numPages, function(){ console.log("New num pages:"+scope.numPages); scope.nPages = parseInt(scope.numPages,10); scope.pages=[]; for (var i=0;i&lt;scope.nPages;i++) { scope.pages.push({value:''+(i+1),text:'Page '+(i+1)}); } }, true); console.log("Watch is bound"); }, controller:function($scope){ $scope.onPrevClick=function(newIndex){ $scope.displayPage = $scope.displayPage -1; } $scope.onNextClick=function(newIndex){ $scope.displayPage = $scope.displayPage +1; } $scope.onFirstClick=function(newIndex){ $scope.displayPage = 1; } $scope.onPrevClick=function(newIndex){ $scope.displayPage = $scope.numPages; } }, template:"&lt;div style='clear:both' class='pagination'&gt;&lt;ul &gt;"+ "&lt;li&gt; &lt;a ng-click=\"\"&gt;First&lt;/a&gt;&lt;/li&gt;"+ "&lt;li &gt;&lt;a ng-click=\"\"&gt;Previous&lt;/a&gt;&lt;/li&gt;"+ "&lt;li &gt;&lt;a ng-click=\"\"&gt;Page :&lt;select ng-model='displayPage' "+ " ng-options='option.value as option.text for option in pages' ng-change=\"gotoPage()\"&gt;"+ "&lt;/select&gt;&lt;/a&gt;&lt;/li&gt;"+ "&lt;li &gt;&lt;a ng-click=\"\"&gt;Next&lt;/a&gt;&lt;/li&gt;"+ "&lt;li &gt;&lt;a ng-click=\"\"&gt;Last&lt;/a&gt;&lt;/li&gt;"+ "&lt;/ul&gt;&lt;/div&gt;" }; }) </code></pre> <p>usage</p> <pre><code>&lt;div my-paginator num-pages='numPages' display-page='currPage'&gt;&lt;/div&gt; </code></pre> <p>The numPages get changed every time user picks a new category. The problem I am facing is the $watch on the numPages is never invoked even if the value is changed in the table</p>
 

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