Are there AngularJS data update callbacks? How do I manually update page when data changes?

前端 未结 1 751
再見小時候
再見小時候 2021-02-06 19:20

I went through the AngularJS tutorial and it\'s pretty neat. I\'ve also dipped into Backbone and Ember.js (though not totally familiar with either) but I\'ve heard lots of prais

相关标签:
1条回答
  • 2021-02-06 19:36

    In a directive, you could $watch for a change on your list of cars and reapply the markers on your map. I am not familiar with Google Maps programming, but here's an attempt to illustrate what I talking about: http://plnkr.co/edit/d8Dn6epgnQ9UvWrMDAk8?p=preview

    EDIT:

    I found a great way of keeping track of the filtered results:

    <tr ng-repeat="item in (filteredcars = (cars | filter: query))">
    

    This create on the fly the variable filteredcars and no need to bind a change event on the input query!

    So to recap:

    1) You can $watch data for change. But don't forget the 3rd parameter to tell it is an array.

    scope.$watch('myvar', function(newval, oldval) {...}, true);
    

    2) You can create a variable on the fly containing the filtered results of an expression coming from an ng-repeat.

    3) Don't forget to empty the map element before you append child elements, otherwise, the filtered elements won't appear to be working.

    0 讨论(0)
提交回复
热议问题