underscore.js - How do I ask AngularJS to recalculate the value of a complex function? -
i have angularjs controller following function:
$scope.getexamplevalue = function(exampleid) { // calculate value using underscore's _.where() // clause against 2 json arrays on $scope // , exampleid parameter passed in return computedvalue; }
the function's parameter (exampleid
) rendered server, resulting html looks this:
<div ng-controller="examplecontroller"> ... <span>{{ getexamplevalue(3) }}</span> <span>{{ getexamplevalue(4) }}</span> <span>{{ getexamplevalue(5) }}</span> ... </div>
the problem have angularjs doesn't know call getexamplevalue()
again when json arrays used in function have changed: they're 2 simple json arrays, new json items can added or removed, or properties of existing json items in either array can modified affect result.
i've looked @ $scope.watch()
, $scope.watchcollection()
i'm unsure how can use them without changing approach bind against computed values rather against function prefer.
essentially think i'm asking how notify angularjs complicated bound value has changed, wrap notification in $scope.watch()
..
thanks help.
you looking $scope.$apply
:
when change json asyncly, run:
$scope.$apply(function () { // update properties on $scope });
Comments
Post a Comment