Read full article on the Infragistics blog In this blog post, we will learn about ViewChild and ContentChild in Angular. Essentially ViewChild and ContentChild are used for component communication in Angular. Therefore, if a parent component wants access of child component then it uses ViewChild or ContentChild. Any component, directive, or element which is part of a template is ViewChild and any component or element which is projected in the template is ContentChild. ViewChild and ViewChildren If you want to access following inside the Parent Component, use @ViewChild decorator of Angular. Child Component Directive DOM Element ViewChild returns the first element that matches the selector. Let us assume that we have a component MessageComponent as shown in the below listing: We are using MessageComponent inside AppComponent as shown in below listing: In application, you will get the output as below: Here, MessageComponent has become child of AppComponent. Therefore, we can access it as a ViewChild.
I guess you came to this post by searching similar kind of issues in any of the search engine and hope that this resolved your problem. If you find this tips useful, just drop a line below and share the link to others and who knows they might find it useful too.
Stay tuned to my blog, twitter or facebook to read more articles, tutorials, news, tips & tricks on various technology fields. Also Subscribe to our Newsletter with your Email ID to keep you updated on latest posts. We will send newsletter to your registered email address. We will not share your email address to anybody as we respect privacy.
Stay tuned to my blog, twitter or facebook to read more articles, tutorials, news, tips & tricks on various technology fields. Also Subscribe to our Newsletter with your Email ID to keep you updated on latest posts. We will send newsletter to your registered email address. We will not share your email address to anybody as we respect privacy.
This article is related to
angular,ContentChild,ViewChild
angular,ContentChild,ViewChild
0 Comments