javascript - How to avoid reentrancy in AngularJS? -
bootstrap selectpicker hides original select , creates additional element filling options select. when using ngoptions selectpicker doesn't automatically updates itself.
so i've created directive listens ngoptions collection changes , calls element.selectpicker()
it works fine if no filtering applied ngoptions. otherwise filering function returns new array each time called causes $watch callback fire recreates selectpicker. angular detects dom has changed , starts new digest cycle infinitely looping process. after 10 iterations angular expected throws exception.
i need temporarily unsubscribe watch when creating selectpicker und later subscribe again when digest cycles finished. possible?
update1
thougt little more , have idea try. filter defines factory returning filtering function can use captured array store filtered content - reference won't change listener fire when contents of collection changes.
about temporarily stop watching:
$watch
returns unwatch function afaik:
var stopw = $scope.$watch('data', process); stopw(); //anywhere
also small advice. don't want compare '===' when watching.
try use function, detects changed:
$watch(function(){return $scope.data.list;}, process);
or even:
$watch(function(){return json.stringify($scope.data);}, process);
the last 1 should ignore array recreates filter.
Comments
Post a Comment