Is it possible to cast back ElementRef to a component.
I have a situation where I have in my hand the nativeElement and I need to cast it to a component.
Have a look at the console.log, I want to extract the name, Can I cast it back?
Thanks
https://stackblitz.com/edit/angular-8aoq7f?file=src%2Fapp%2Fapp.component.ts
@Component({
selector: 'my-app',
template: `<sub-component [name]="'test'"></sub-component>`,
})
export class AppComponent {
constructor(private ref : ElementRef){
console.log((<SubComponent>this.ref.nativeElement).name); //<--- .name is undefined
}
}
@Component({
selector: 'sub-component',
template: `<div>{{name}}</div>`,
})
export class SubComponent {
@Input() name : string
}