I have an Angular 2 application that needs to access to a JSON variable called "configuration" which has been passed as a "POST" parameter to the application itself.
With Angularjs, I used ng-init this way:
<html lang="it" ng-app="myApp" ng-init='configuration=<%- configuration %>'>
And I could access to that variable using $scope.configuration. But what about Angular 2? The only way I found to make this variable usable from the application is putting it inside a not-visible div, inside index.html page.
<body><div id="getConfig"><%- configuration %></div>
<app>Loading...</app>
</body>
And inside app.component.ts...
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app',
templateUrl: './app-fe/app.component.html'
})
export class AppComponent {
private title:string = 'Hello World';
private configuration = document.getElementById("getConfig").innerHTML;
constructor() {
console.log('=== app started ===');
console.log(this.configuration);
};
}
But something tells me this is not the best way...