Directives can become disconnected in several ways:

When AsyncDirectives are disconnected, their disconnected callback is called. Async directives should implement disconnected to unsubscribe from async callbacks so that the directive can be garbage collected. Internally, directives hold references to the underlying DOM they are associated with, so failing to unsubscribe disconnected directives can lead to memory leaks.

Add a method that stops the timer:

Add the disconnected callback, and call our ensureStopped() callback since we don't want that running if the directive is no longer in use:

Finally, implement the reconnected callback.

If a directive instance has been disconnected, it is possible for that same instance to be reconnected if the DOM it was rendered into is subsequently reconnected. This can happen when DOM is removed and cached for later use, or when a host element is moved, causing a disconnection and reconnection.

Here, we'll just re-start the timer using our ensureTimerStarted method:

Always implement reconnected after implementing disconnected.

As a rule of thumb, if you implement disconnected to stop some async work, you should always implement reconnected to put the directive back into a working state.