I have a question about Angular 4 in general.
One of my co-workers created a reference of an AComponent and bound it as a property to a BComponent to access AComponent's properties, instead of binding AComponent's properties individually. Then he also subscribes to an observable in the AComponent.
Here is the idea:
// a.component.ts
@Component({
selector: 'some-a',
template: `<some-b [someRefToAComponent]="someRefToThis">...</some-b>`
})
export class AComponent {
someRefToThis = this;
someObservable: Observable<any>;
}
// b.component.ts
@Component({
selector: 'some-b',
template: `...`
})
export class BComponent {
@Input() someRefToAComponent: AComponent;
someSubscription: Subscription<any>;
ngOnInit() {
this.someRefToAComponent.someObservable.subscribe(...);
}
ngOnDestroy() {
this.someSubscription.unsubscribe();
}
}
Here is my question: Is this a bad practice or a very bad practice? And additionally: What could happen in such a case? Could it lead to a memory leak?
Would be interesting to know what happens since I don't have that deep insights into Angular's internal functionality, yet.