javascript - Query string in Angular 2 -


how can use query string route in angular 2, query string not required. query string optional.

i read angular doc, in link: https://angular.io/docs/ts/latest/guide/router.html, don't understand.

from docs linked:

the url query string ideal vehicle conveying arbitrarily complex information during navigation. query string isn't involved in pattern matching , affords enormous flexiblity of expression. serializable can appear in query string.

when define routes, don't need specify query string parameters expected (or unexpected).

you need use routeparams service query values.

import {router, routeparams} 'angular2/router';  // declare class, ... constructor(     routeparams: routeparams) {   console.log(routeparams.get('myquerystring')); // must exist } 

if value optional (like want), can call params object, , check yourself:

console.log('myquerystring' in routeparams.params()); // true or false 

Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -