Reputation: 13826
How do I get the contents of my current component?
Say I have FooComponent
that's used in another component, like so:
<foo>bar</foo>
How do I extract bar
in FooComponent
?
Tried this, but got val = null
:
ngAfterViewInit() {
console.info('val =', this.elementRef.nativeElement.value);
}
Upvotes: 0
Views: 278
Reputation: 1024
I've created one stackblitz for you in which I've created a tabs component and that tabs component has 3 tabs and I'm passing 3 different templates from app component to tabs component. I think this will give you a better understanding of passing data to a component and how to create a custom component.
https://stackblitz.com/edit/angular-ck6nch?file=app%2Fapp.component.ts
Upvotes: 0
Reputation: 13826
Ahh, found it:
this.elementRef.nativeElement.innerHTML
And to the template add:
<ng-content></ng-content>
Upvotes: 1