Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $scope.Model = { items: [] };
- scope.onAdd = function(e) {
- items.push({
- // properties
- Label: function(item) { // some code that computes the value of label as the item changes }
- });
- };
- <div ng-repeat="item in Model.items track by $index">
- <div>{{ item.Label(item) }}</div>
- <div>{{ item.Name }}</div>
- </div>
- // directive setup
- function(scope, element, attributes) {
- var getter = $parse(attributes.ngModel),
- setter = getter.assign,
- data = {};
- // some kind of crazy code to get things from database
- // and assign it to 'data'
- // next, assign the Label() function to each item, since it
- // wouldn't exist right out of the database
- angular.forEach(data.items, function(value, key) {
- value.Label = function(m) { // normal label code // };
- });
- // assign the data with the attached functions to the model
- setter(scope, data);
- }
- // setup controller code
- // setup the model
- $scope.Label = function(m) {
- return //{stuff happens with m here};
- }
- <div ng-repeat="item in Model.items track by $index">
- <div>{{ Label(item) }}</div>
- <div>{{ item.Name }}</div>
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement