toddmotto / angularjs-styleguide

AngularJS styleguide for teams
https://ultimateangular.com
5.96k stars 700 forks source link

When a statefull component won't trigger $onChanges immediately (External Libraries) #103

Closed caioiglesias closed 8 years ago

caioiglesias commented 8 years ago

Changes to a statefull parent component don't propagate down to the stateless component immediately when using an external library, because things happened outside angular, so changes only apply on the next eventual digest cycle. The only workaround I see to actually not go for a $scope injection and an $apply() is actually wrapping a $q promise and resolving or wrapping the change in a $timeout.

I have seen this when using an external library in a service injected in a statefull component, such as firebase (and they recommend $timeout), or passing an event from a stateless child component to a parent's statefull component using an event from a library such as leaflet.

Is there an alternative to these $q / $timeout practices?

toddmotto commented 8 years ago

Using $timeout would be the best way, it's a safe-$apply() call in effect (the way you're intending to use it). Would be interested to see the code though to see if there's a better way :)

caioiglesias commented 8 years ago

Thank you. It's already clear enough, but I will provide a leaflet/angular sample

caioiglesias commented 8 years ago

I see the shame woman behind me