How to style ng-content

Content inside <ng-content> is insulated from the component. It can’t see the component’s attributes or styling. If you do need to style it, and sometimes you will, you have two options: 1. Just write CSS You can create a regular CSS file and style the content like that. You are almost certainly using the shadow …

Read more

Getting reference to child component in parent component [duplicate]

You can use ViewChild <child-tag #varName></child-tag> @ViewChild(‘varName’) someElement; ngAfterViewInit() { someElement… } where varName is a template variable added to the element. Alternatively, you can query by component or directive type. There are alternatives like ViewChildren, ContentChild, ContentChildren. @ViewChildren can also be used in the constructor. constructor(@ViewChildren(‘var1,var2,var3’) childQuery:QueryList) The advantage is that the result is …

Read more

Get reference to a directive used in a component

You can use exportAs property of the @Directive annotation. It exports the directive to be used in the parent view. From the parent view, you can bind it to a view variable and access it from the parent class using @ViewChild(). Example With a plunker: @Directive({ selector:'[my-custom-directive]’, exportAs:’customdirective’ //the name of the variable to access …

Read more