Angularjs Angular2$location.search()等效项(设置查询参数)
我的web应用程序具有多个过滤器,这些过滤器应在当前Url中表示,以便用户可以简单地复制/标记当前页面,以便稍后将其取回 在angular1中,我使用Angularjs Angular2$location.search()等效项(设置查询参数),angularjs,angular,Angularjs,Angular,我的web应用程序具有多个过滤器,这些过滤器应在当前Url中表示,以便用户可以简单地复制/标记当前页面,以便稍后将其取回 在angular1中,我使用$location.search(名称、值)简单地设置更改时的搜索参数。现在我想在angular2中得到类似的东西 还是错了?我想你必须使用Angular2内部的路由器。代码示例: import {Component} from 'angular2/core'; import {RouteConfig, ROUTER_DIRECTIVES} fro
$location.search(名称、值)
简单地设置更改时的搜索参数。现在我想在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 {
}
从'angular2/core'导入{Component};
从“angular2/ROUTER”导入{RouteConfig,ROUTER_指令};
从“/profile.component”导入{ProfileComponent};
@组成部分({
选择器:“我的应用程序”,
模板:`
`,
指令:[路由器指令]
})
@线路图([
{path:'/profile/:id',name:'profile',component:ProfileComponent}
])
导出类AppComponent{
}
:id是一个路由参数,您可以执行如下URL操作:
/profile/2和2是id参数的值
您可以在Angular2文档中找到更多详细信息:谢谢,但是如果我有多个可选参数呢?在这种情况下,您必须使用queryParams,并且StackOverflow上有一个链接: