5

My web application has multiple filters that should be represented in the current Url so that users can simply copy/bookmark the current page to get it back later.

In angular1 I used $location.search(name, value) to simply set seach params on change. Now I want to get something similar in angular2.

Or is it wrong?

1 Answer 1

2

I think you must use the 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 {
}

The :id is a route parameter and you can do an URL like that: /profile/2 and 2 is the value of the id parameter.

You could find more detail in the Angular2 doc : router doc

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you, but what if I have multiple optional parameters?
You must use queryParams in this case and there is a link on StackOverflow for that: route optional parameters

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.