admin管理员组

文章数量:1317898

In angular I found out you can bind a template to a function which returns an array, like this:

<div class="cal_row" id ="id_{{task.id}}" ng-repeat="task in calendar.filtered()">
  <div class="id">{{task.id}}</div>
      <div class="task">{{task.task}}</div>
  <div class="start">{{task.start}}</div>
  <div class="finish">{{task.finish}}</div>
</div>

It's pretty cool, because that way I can, for example, avoid having to keep a variable around just to maintain the filtered version of the data.

However, I also loose the binding with the original data: when the underlying data changes, I can't seem to get angular.js to spot the change, and update the view.

Is there a way to do that? I tried to find anything in the docs, but couldn't

Thanks a lot

In angular I found out you can bind a template to a function which returns an array, like this:

<div class="cal_row" id ="id_{{task.id}}" ng-repeat="task in calendar.filtered()">
  <div class="id">{{task.id}}</div>
      <div class="task">{{task.task}}</div>
  <div class="start">{{task.start}}</div>
  <div class="finish">{{task.finish}}</div>
</div>

It's pretty cool, because that way I can, for example, avoid having to keep a variable around just to maintain the filtered version of the data.

However, I also loose the binding with the original data: when the underlying data changes, I can't seem to get angular.js to spot the change, and update the view.

Is there a way to do that? I tried to find anything in the docs, but couldn't

Thanks a lot

Share Improve this question asked Jul 17, 2012 at 11:17 simonesimone 5,2334 gold badges29 silver badges59 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

If you make a change to some data from outside angular, you have to use $myScope.$apply so angular knows something has changed. http://docs.angularjs/api/ng.$rootScope.Scope#$apply

本文标签: javascriptDatabinding a function in AngularjsStack Overflow