javascript - Watch array changes in AngularJS service -
i have service object exposes array watch changes (within service) , phone call method.
this trivial within controller watching changes array on it's $scope, how can same accomplished in service? service shared in several controllers , don't want implement logic in many places.
i have tried using polymer's arrayobserver, doesn't seem work angular.
does have suggestions? thanks
you can add together watch on $rootscope, i.e.:
.service("mysvc", function($rootscope,...) { var myarray = ... ... $rootscope.$watchcollection( function() { homecoming myarray; }, function(newval) { ... } ); however have careful unregister watch when (if) no longer needed.
javascript angularjs
No comments:
Post a Comment