Skip to content

on-watch rule also triggers for service/provider/runblock #378

@Bennit

Description

@Bennit

The on-watch rule only makes sense to me in the context of a limited lifetime code block such as a controller. For services there are no destroy points so there's no point in making sure it's unassigned.
I have to disable the rule or capture it in a variable (which is then unused, triggering another warning).

A concrete example indicating why the on-watch rule should not be triggered in the case of service/provider/runblock:

I'm using UI-router and I want to listen to the $rootScope emitted event '$stateChangeSuccess' to track page changes in google analytics. So I attach a listener via $rootScope.$on in a method of Analytics service. (Originally the listener was attached in a run block but then I learned you should avoid having logic inside of run blocks to improve testability). This however results in a warning from the angular/on-watch rule as the listener is not captured in a variable to be destroyed later.

Metadata

Metadata

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions