Issue
I make some example with ViewChild - this is what i want to do with Inject. simple expamle
I try provide this service in parent component but i get different service. Next i try make somethink like this but i dont want to write provide section in my new Modules... I want just somehow inject service from child...
Solution
you can inject something from "child's" injection subtree with the help of read attribute
@ViewChild(ChildComponen, {read: TestService}) testS: TestService;
but it is being initialized in the after view init stage of the component and in most cases it will cause ExpressionChangedAfterItHasBeenCheckedError in dev mode or your view will not react properly to the update in prod mode.
It can still be used, but you should understand angular change detectionn and be carefull with usage of such non typical things
Answered By - Andrei
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.