javascript - AngularJS: Can't get a value of variable from ctrl scope into directive -


hostingctrl:

function hostinglistctrl($scope, hosting) {      hosting.all().success(function(data) {         $scope.hostings = data;     });  } 

html template:

 <pagination items-count="{{hostings.length}}" current-page="currentpage" items-per-page="{{itemsperpage}}"></pagination> 

directive:

admin.directive('pagination', function() {     return {         restrict: 'e',         replace: true,                 templateurl: "<%= asset_path('angular/templates/ui/pagination.html') %>",         scope: {                         currentpage: '=',             itemscount: '@',             itemsperpage: '@'         },         controller: function($scope, $element, $attrs) {             console.log($scope);             console.log($scope.itemscount);                   },         link: function(scope, element, attrs, controller) {                                  }     }; }); 

i'm trying hold of value of itemscount variable in directive when try console.log it, value empty. strange thing when console.log whole scope, it's there:

scope {$id: "005", $$childtail: null, $$childhead: null, $$prevsibling: null,   $$nextsibling: null…}   $$asyncqueue: array[0]   $$childhead: null   $$childtail: null   $$destroyed: false   $$isolatebindings: object   $$listeners: object   $$nextsibling: child   $$phase: null   $$prevsibling: null   $$watchers: array[3]   $id: "005"   $parent: child   $root: scope   currentpage: 1   itemscount: "11"   itemsperpage: "5"   this: scope   __proto__: object 

also when check html source

<nav class="pagination" items-count="11" current-page="currentpage" items-per-page="5"> 

with isolate scope , @ notation, need use $attrs.$observe('itemscount', function(value) { ... }.

see http://docs.angularjs.org/guide/directive#attributes

when controller (and link) functions first execute, @ properties not populated yet. see value in log because time expand $scope object, value has been populated.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -