How to load Angular 2 application only after getting external data?
For example, there is external application on the same html page, I need pass some data to my app service. Imagine, this is API URL, like 'some_host/api/'
and my application should not be initialized till getting this information.
Is it possible to call some method of the my application from external app script like:
application.initApplication('some data string', some_object);
index.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>App</title>
<base href="/">
<link>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<script>
application.initApplication('api/url', some_object);
</script>
<app-root
>Loading...</app-root>
</body>
</html>
Here is something to start with: plnkr: https://plnkr.co/edit/b0XlctB98TLECBVm4wps
You can set the URL on the window object: see
index.html
below. In your root component, add*ngif="ready"
where ready is a public member of your root component that is set to false by default.Then use that URL in your service/root component with http service, once the request is successful you can set ready to true and your app will show: see
app.ts
app
componentngOnInit
method.Code:
File:
src/app.ts
File:
src/data.json
File:
src/index.html