ng-init not initialize data in pagination, angularjs -


i'm using angularjs , angular pagination show users detail. here, use ng-init initialize age of users. if there age in user's detail show otherwise show default age 10. please see plunker

ng-init works fine first time when move next page not showing default age i.e.10. example: in page 3, name name30 , there no age. so, age should come default age.

nginit directive allows evaluate expression in current scope. problem approach nginit called once when scope created - works page 1.

also check out says in angularjs documentation:

the appropriate use of nginit aliasing special properties of ngrepeat, seen in demo below. besides case, should use controllers rather nginit initialize values on scope.

so based on recommendation better set default age value in controller like:

  // assign value on page change.   $scope.loadrecord = function(page) {     $scope.user = $scope.users[page-1];      if (!$scope.user.age) {       $scope.user.age = 10;     }   };    // initial value   $scope.loadrecord(1); 

please check out plunker se in action.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -