My link is: http://localhost:4200/EditQuestionnaire;id=1;name=Random Questionnaire
And in ngOnInit() I am executing this code but cannot get the values
ngOnInit(): void {
this.route.params.subscribe(params => {
this.questionnaireName = params['name'];
this.questionnaireID = params['id'];
}
CodePudding user response:
You can use ActivatedRoute
as below
constructor(private activeRoute: ActivatedRoute){
this.activeRoute.queryParams.subscribe(params => {
this.questionnaireName = params['name'];
this.questionnaireID = params['id'];
});
}
And your url should correct as http://localhost:4200/EditQuestionnaire?id=1&name=Random Questionnaire
CodePudding user response:
public id:string;
constructor(private activatedRoute: ActivatedRoute){
this.id = this.activatedRoute.snapshot.params.id;
}