1

I'm not necessarily talking about a child component, so ViewChild isn't an option.

Is it possible to inject any component into another component? I found this question, but it's outdated.

What's the best way to achieve this?

Community
  • 1
  • 1
maximedupre
  • 3,597
  • 4
  • 24
  • 56

1 Answers1

0

It seems like what you want is a service to manage an Observable/Subject that both components can access.

See this answer for an implementation example Delegation: EventEmitter or Observable in Angular2

And for reference, here is a list of ways to currently interact between different components: https://angular.io/docs/ts/latest/cookbook/component-communication.html

Community
  • 1
  • 1
Simon Briggs
  • 1,081
  • 1
  • 8
  • 14
  • I do not wish to only communicate between components, I need to obtain a reference to the component instance itself. – maximedupre Dec 27 '16 at 15:13
  • It's not possible as far as I know. You need to use ViewChild or ViewChildren if you want to reference the object. But I don't see what you can't achieve by storing state in a service? – Simon Briggs Dec 28 '16 at 02:23