Reputation: 1868
<body>
<app-root data="myData"></app-root>
</body>
I need to retrieve myData
that I will manually add at index.html
and use it into a component.
How can I retrieve this data?
Thanks.
Upvotes: 1
Views: 1588
Reputation: 877
I believe this answer has what you need:
https://stackoverflow.com/a/43544999/3581932
Use @Attribute (for Angular 4)
index.html :
<my-app myAttribute="myAttributeValue">
<div>Loading...</div>
</my-app>
app.component.ts :
@Component({
selector: 'my-app',
templateUrl: 'app.component.html',
styleUrls: ['app.component.css']
})
export class AppComponent {
constructor(private elementRef:ElementRef) {
let myAttribute = this.elementRef.nativeElement.getAttribute('myAttribute');
}
}
[Copied directly from above post]
Upvotes: 2