Angular2 $ location.search () equivalent (query request parameters)

There are several filters in my web application that need to be presented in the current url so that users can simply copy / mark the current page to return it later.

In angular1, I used $location.search(name, value) to just set seach options when changing. Now I want to get something like this in angular2.

Or is it wrong?

+5
source share
1 answer

I think you should use a router inside Angular2. Code example:

 import {Component} from 'angular2/core'; import {RouteConfig, ROUTER_DIRECTIVES} from 'angular2/router'; import {ProfileComponent} from './profile.component'; @Component({ selector: 'my-app', template: ` <router-outlet></router-outlet> `, directives: [ROUTER_DIRECTIVES] }) @RouteConfig([ {path: '/profile/:id', name: 'Profile', component: ProfileComponent} ]) export class AppComponent { } 

Parameter: id is the route parameter, and you can make such a URL: / profile / 2 and 2 is the value of the id parameter.

More information can be found in the Angular2 doc document: router doc

+2
source

Source: https://habr.com/ru/post/1247356/


All Articles