2

I've got a directive that manipulate DOM, and than a 3rd party script:

// manipulate DOM
var elButton = angular.element('<button></button>');
element.append(elButton);

// 3rd party-service that is to manipulate elButton again.
externalService.do(attrs.someAttr);

Angular seems to digest my changes only after externalService.do() is happening, so externalService has no chance to do his magic.

Is there any way to force angular to apply its changes to the view? $apply and $digest throw an error, $timeout of 500ms solved the problem in my fast machine, but fail to do that in slower machines, and anyway I want to avoid using timeout.

The 3rd party service I use is Optimizely (A/B testing service). I didn't find any resource that solves this problem.

Thanks!

SRachamim
  • 931
  • 2
  • 8
  • 20
  • can you put up a demo illustrating the problem? – codef0rmer Jul 01 '14 at 08:13
  • look to see if the library that you are using, in this case Optimizely, provides a way for you to use a callback when their code is done (or maybe it returns a promise). That way you can then do your logic in that callback (and call $scope.$apply). – JoseM Jul 01 '14 at 15:29
  • But I need to do my logic before Optimizely do theirs. – SRachamim Jul 01 '14 at 15:41
  • OK, so I dug into to code Optimizer is executing and I noticed their generated code is wrong (using wrong element class!). Now the problem doesn't exist! Thanks anyway! – SRachamim Jul 01 '14 at 19:17

0 Answers0