Is it feasible to return a reference from a component class with a custom interface implemented to the injected service class in my Angular 6 project?
Here is an example of what I am aiming for.
ServiceClass
@Injectable()
export class MyService {
constructor(private parent: MyComponent){ // <- Somehow get a reference from the component I inject this into?
parent.doStuff();
}
}
ComponentClass
@Component({
selector: 'project-a-component',
template: `
<div>stuff</div>
`,
styleUrls: ['./a.component.scss']
})
export class AComponent implements MyComponent {
constructor(private myService: MyService){ }
doStuff(): void {
console.log('yey!');
}
}
Edit: My goal is to listen to the OnDestroy event for a component in order to run .pipe(takeUntil(parent.isDestroyed)) to unsubscribe a subscription without having to add it manually every time I use my services in my project or pass a reference to my parent component in each method call. Having the reference available in the constructor (or just one place) would be ideal. Trying to explain the issue as clearly and simply as possible.