Advertisement
Guest User

Untitled

a guest
Apr 25th, 2014
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. $scope.slugs = [
  2. {id: 1, name: 'angular-directives'},
  3. {id: 23, name: 'composing-your-very-own-angular-directives'},
  4. {id: 70, name: 'directives-in-angular-js'},
  5. ];
  6.  
  7. $scope.slugs=[{id:1,name:'angular-directives'},{id:23,name:'composing-your-very-own-angular-directives'},{id:70, name:'directives-in-angular-js'}];
  8. $scope.names=[]; //for ng-list
  9. $scope.newSlugs = [];
  10.  
  11. //loop through every element in array slugs
  12. $scope.slugs.forEach(function(ele,index,array){
  13. //for ng-list
  14. $scope.names.push(ele.name);
  15. //create a new obj with one attribute 'name'
  16. $scope.newSlugs.push({name:ele.name});
  17. //register observer to every slug, update the name of obj in newSlugs once user had updated the name
  18. $scope.$watch("names["+index+"]",function(newValue,oldValue){
  19. $scope.slugs[index].name=newValue;
  20. $scope.newSlugs[index].name=newValue;
  21. });
  22. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement