My question would be regarding angular 4, how to get route params, if for example a user gets on your page with, instead of the default url, like for example http://localh
If all you want to do is log the params.id
; try using the ActivatedRouteSnapshot
like this.
ngOnInit() {
console.log(this.route.snapshot.params.id);
}
If you want to check if the params.id
is present, maybe do something like:
import {Component, EventEmitter, Input, OnInit, ViewChild} from '@angular/core';
import { ActivatedRoute, ParamMap} from '@angular/router';
@Component({
selector: 'hook',
templateUrl: 'hook.component.html',
styleUrls: ['hook.component.scss']
})
export class HookComponent implements OnDestroy, OnInit {
hasId: boolean = false;
constructor(private route: ActivatedRoute) {
}
ngOnInit() {
if(this.route.snapshot.params.id !== null)
{
// do magic....
}
}
}