You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 4, 2017. It is now read-only.
Many apps would like to pass information from the host web page to the Angular app on the page. That A2 app is the root component.
The desired information is typically generated into the web page by a server-side rendering engine, e.g., rendering in a Node Express app, razor output in an ASP.NET MVC app.
The following describes much of what this cookbook would demonstrate.
There are at least three ways info could arrive:
as an attribute value generated into the app root element attribute: <my-app name="John Doe"></my-app>
as data generated into the page as a JavaScript/JSON value accessible from window.document
as values generated into the HTML (visible or invisible) within a well-known tag, in a manner the app can interpret.
1. Attribute value case
A root component can't bind to inputs because it sits above all other components; there is no parent component to bind to. So we can't treat name="John Doe" as an input property binding. Per angular issue #1858, we can inject elementRef and get the attribute value from there.
2. JavaScript data case
Can create a service to access data in window.document and provide that service during bootstrapping. See Rob's example in angular issue #1858.
3. Data-in-page case
The solution is a variation on (2) in which the service extracts the in-page data as innerHtml and turns it into data for the app to consume.
clemgrim, alkemist, zoechi, yeelan0319, emilio-martinez and 5 more