Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular2 queryParams throws "does not exist on type" error

I got an Angular2-service that should return parameters from an URL like http://localhost:3001/?foobar=1236

import { Injectable } from '@angular/core';
import { ActivatedRoute }     from '@angular/router';
import 'rxjs/add/operator/map';

@Injectable()

export class ParameterService {
  constructor(private route: ActivatedRoute) {  }

  getParameter() {
    return this.route.snapshot.queryParams.foobar;
  }
}

But when I call the getParameter() method of the service I get the error:

error TS2339: Property 'foobar' does not exist on type '{ [key: string]: any; }'

and after the error it returns the correct result. I can access the foobar parameter with the debugger without any problems. did someone had a similar issue? I could imagine that it gets called to early?

(possible duplicate: angular2 rc6: Property queryParams does not exist on type RouterState)

like image 978
Peter Piper Avatar asked Jan 06 '23 08:01

Peter Piper


1 Answers

This is how you get parameters:

this.route.snapshot.queryParams['foobar'];
like image 111
Stefan Svrkota Avatar answered Jan 13 '23 08:01

Stefan Svrkota