Angular 4 forwardRef?

I bought an Angular 4 template to see how the layout is executed, but includes working components. I noticed that they have a set of settings in the application component, which is mainly intended for menus, changing styles, mainly controlling the external structure.

In the menu component and several other components, they exchange data with AppComponent settings using the following:

constructor(@Inject(forwardRef(() => AppComponent)) public app:AppComponent) {} 

and will call something like: this.app.darkMenu = true in the menu component

Is this the right project, good, bad, outdated? I did not even know that you can communicate with the App or the parent component, how is it? Should it be an observable subject or an EventEmitter or is it acceptable to communicate via forwardRef? It seems to be like .NET, where I could communicate with MasterPage using this.master.whateverproperty.

I like how forwardRef works, but not sure if I should use it or change it to communicate differently ??

+7
angular primeng
source share
1 answer

forwardRef not for communication. forwardRef should use a type name that is declared later in a single file.
If the export class AppComponent {} is in another file, there is no need for forwardRef .
IMHO it is usually better to use a common service for communication between components that are not direct parent-child.

+4
source share

All Articles