2

I tried to do that in ngOnInit() like:

ngOnInit() {
    this.route.queryParams
      .filter(params => params.type)
      .subscribe(params => {
        this.tab = params.type;
        this.setHeader();
      });
  }

My URL is:

http://localhost:4200/s/6/t/p/create/1

Routing is:

{path: ':Id/t/p/create/:type', component: CalendarComponent},
2
  • You have 6 params in your url and five in the routing. Check that to start with. Commented Dec 6, 2017 at 14:32
  • Possible duplicate of How get value from url in angular 2 Commented Dec 6, 2017 at 14:57

2 Answers 2

3

try that :

this.route.snapshot.params["page"]

the page is the query param so the route must be like that

const routes: Routes = [
  {
    path: 'page/:page',
    component: OrdersComponent,
    data: {
      title: 'Orders'
    }
  }
]

don't forget the add the route into the constructor

constructor(private route: ActivatedRoute) { }

and the import

import {ActivatedRoute} from "@angular/router";
Sign up to request clarification or add additional context in comments.

4 Comments

if you want use the Observable : this.route.queryParams.subscribe(params => this.page = +params['page']; );
Why page inside this.route.snapshot.params["page"]?
this.route.snapshot.params it's an array of all query params so to access directly the param page use this.route.snapshot.params["page"]
for your case change it by type
0

Try

this.route.params.subscribe(params => {
    this.tab = params.type;
    this.setHeader();
  });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.