Advertisement
Guest User

Untitled

a guest
Sep 17th, 2014
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. $scope.Model = { items: [] };
  2.  
  3. scope.onAdd = function(e) {
  4. items.push({
  5. // properties
  6. Label: function(item) { // some code that computes the value of label as the item changes }
  7. });
  8. };
  9.  
  10. <div ng-repeat="item in Model.items track by $index">
  11. <div>{{ item.Label(item) }}</div>
  12. <div>{{ item.Name }}</div>
  13. </div>
  14.  
  15. // directive setup
  16. function(scope, element, attributes) {
  17. var getter = $parse(attributes.ngModel),
  18. setter = getter.assign,
  19. data = {};
  20.  
  21. // some kind of crazy code to get things from database
  22. // and assign it to 'data'
  23.  
  24. // next, assign the Label() function to each item, since it
  25. // wouldn't exist right out of the database
  26. angular.forEach(data.items, function(value, key) {
  27. value.Label = function(m) { // normal label code // };
  28. });
  29.  
  30. // assign the data with the attached functions to the model
  31. setter(scope, data);
  32. }
  33.  
  34. // setup controller code
  35. // setup the model
  36. $scope.Label = function(m) {
  37. return //{stuff happens with m here};
  38. }
  39.  
  40. <div ng-repeat="item in Model.items track by $index">
  41. <div>{{ Label(item) }}</div>
  42. <div>{{ item.Name }}</div>
  43. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement