angularjs - Angular2 $location.search() 等效(设置查询参数)

标签 angularjs angular

我的 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/

相关文章:

Angular 2 指令 : How to get created echarts instance in directive?

在多个模块中声明的 Angular2 组件

javascript - 如何使用 AngularJS 过滤日期范围?

javascript - 循环数组Javascript后替换对象属性值中的字符串

angularjs - Bower 调用被公司代理阻止,然后在更新 .bowerrc 时出现错误

angularjs - Angular 2 ng-需要

javascript - Angular 路由

javascript - Angular - 如何将 Angular 对象制作为数组

javascript - Angular2 - 带有数据数组的 react 形式

javascript - 如何验证两个不同的azure应用程序?