I'm trying to get the [param] from url, and get some information throw a service with this param, and then (ONLY then) go to another page.
Chome URL: http://localhost:4200/login/asd
appmodule:
{ path: 'login/:token', component: AppComponent},
appcomponent.ts
ngOnInit() {
this.sub = this.route.params.subscribe(params => {
this.usr = params['token'];
console.log(this.usr); //THIS KEEP GETTING UNDEFINED
});
}
That usr keeps getting undefined, dont know why... Some idea? Thanks.
I tryied things like this:
this.sub = this.route.params.subscribe(params => {
if (!params['token']) {
console.log('NO token'); //GOES HERE EVERYTIME
}
this.token = params['token'];
console.log(this.token);
});
It gets out in 'NO token' every single time.. Something wrong with the url maybe?