Video

Latest

ActivatedRoute





ActivatedRoute Contains the information about a route associated with a component loaded in an outlet. It can also be used to pass data from one componenttoanother component using route such as Id, flag, state etc.

http://localhost:4200/quiz/edit_quiz/032

032 being id of the quiz you wanna edit.

Get this id in your component(in my case let it be edit_quiz.compontent.ts) to use by using Activated Route.



Step 1: Import ActivatedRoute from Router module.

import { ActivatedRoute } from '@angular/router';

Step 2: Inject ActivatedRoute in constructor.

  constructor(private activatedRoute: ActivatedRoute) { }

Step 3: Get id on a local variable named quizId in ngOnInit(){}

   ngOnInit() {
    this.quiz_id = this.activatedRoute.snapshot.params['id'];
   }

Now we have id in edit_quiz.component.ts to use.

No comments