I have the following scenario: a Directive detects changes that happen to an ElementRef, and performs actions when it is destroyed:
Template:
<input doSomethingOnDestory *ngIf="showMyInput" type="text" [(ngModel)]="myInput">
Directive:
@Directive({
selector: '[ngModel][doSomethingOnDestory]'
})
export class DoSomethingOnDestory Directive implements OnDestroy {
@Output() ngModelChange: EventEmitter<any> = new EventEmitter();
constructor(){}
ngOnDestroy() {
//Do something to the model
}
}
Now I've come to a scenario in which I want to run //Do something to the model only if the component is destroyed by itself (for example, by showMyInput becoming falsy) and not by an "outside destroyer" (the whole wrapping component of the form being destroyed, for example)
How can I do that?
Thanks :-)