我的 web 应用程序有多个过滤器,它们应该在当前 Url 中表示,以便用户可以简单地复制/标记当前页面以便稍后取回它。
在 angular1 中,我使用 $location.search(name, value)
来简单地设置搜索参数的变化。现在我想在 angular2 中得到类似的东西。
还是错了?
最佳答案
我认为您必须在 Angular2 中使用路由器。代码示例:
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.
您可以在 Angular2 文档中找到更多详细信息:router doc
关于angularjs - Angular2 $location.search() 等效(设置查询参数),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36692698/