0

I know how ngRepeat uses hash keys to not rerender elements, I am storing a simple array of strings, and I would like to force the re render of the dom , is there a simple way to do it?

to force ng-repeat to re render itself even though my string array havn't changed?

Why :

$scope.image = "image/jpg..." $scope.confs = ['glow','sepia','brighten'] <div ng-repeat="conf in confs"> <div my-directive="conf"> </div> 

I want to rerun the ng-repeat when the image changes, not when the conf change

7
  • 2
    Could you elaborate a bit. If your array hasn't changed, what's the point in re-rendering it? The result will be identical. Commented Dec 14, 2013 at 17:45
  • 1
    curious why you would ever need to do this? can try $apply but if nothing changed in model angular likely won't do anything Commented Dec 14, 2013 at 17:45
  • You still haven't explained why you want to reexecute the ng-repeat, and why it would produce a different result. Commented Dec 14, 2013 at 18:06
  • because the $scope.image has changed, the configuration is still the same but its not the same image, so my-directive is applied on the wrong image. ng-repeat will only change if $scope.confs changes, but i want it to re render when $sope.image changes :/ Commented Dec 14, 2013 at 18:09
  • 1
    Could you show your directive? -- The issue could probably be solved by tweaking it a bit. Commented Dec 14, 2013 at 18:18

1 Answer 1

3

In this case, you don't actually want ng-repeat to rerender, because it will produce exactly the same output: three my-directive divs. Howeer, you DO want all my-directives to rerender, because something they depend on has changed.

What you can do in your directive is set up a $watch on your scope. For example, in my-directive's link function,

scope.$watch( function thingToWatch(){ return $scope.image; }, function whatToDo(image){ .../*your code using image here*/... } ); 

Now, when $scope.image changes, your directives will all update themselves.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.