I'm creating a component that displays validation errors under input fields. If there is an error message shown, and the user submits the form I want to flash the message to draw their attention.
I was wondering if it's possible to use an observable as an input binding?
That way I can subscribe to the input and flash when any data is observed.
Here's an example of my idea:
@Component({..})
export class MessageComponent implement OnChanges {
@Input()
public flash: Observable<any>;
public ngOnChanges(changes: SimpleChanges): void {
if ('flash' in changes) {
(<Observable<any>> changes['flash'].currentValue).subscribe(() => {
// trigger the flash animation here
});
}
}
}
What I can't figure out is if this will leak memory, and how/when should I unsubscribe (or is it even necessary).
Is this kind of practice allowed in Angular?
flash
changing tonull
orundefined
. – Trierarch