Reputation: 977
I have an Angular App, where in the landing page is index.html, this app is accessed from other application and I need to pass arguments into app to be used
Like
http://localhost:4200/myapp/index.html?name=John&role=merchant
where name and role are arguments , angular needs to ready them and store in header object to be used accross the application.
Any ideas how to proceed?
Upvotes: 0
Views: 68
Reputation: 7
Below code give you current Url using array functions you can get name and role:-
let currentUrl = this.router.url;
You can append header as below:-
var headers = new Headers();
headers.append('name', this.name);
headers.append('role', this.role);
Upvotes: 0
Reputation: 1885
This may help for you:
name:string;
role:string;
ngOnInit() {
this.sub = this.route.params.subscribe(params => {
this.name= params['name']; // (+) converts string 'id' to a number
this.role= params['role'];
});
}
Upvotes: 2