加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – Angular2 $location.search()等价物(设置查询参数)

发布时间:2020-12-17 07:14:38 所属栏目:安全 来源:网络整理
导读:我的Web应用程序有多个过滤器,应该在当前的Url中表示,以便用户可以简单地复制/书签当前页面以便以后将其恢复. 在angular1中,我使用$location.search(name,value)来简单地在变化时设置seach参数.现在我想在angular2中得到类似的东西. 还是错了? 解决方法 我
我的Web应用程序有多个过滤器,应该在当前的Url中表示,以便用户可以简单地复制/书签当前页面以便以后将其恢复.

在angular1中,我使用$location.search(name,value)来简单地在变化时设置seach参数.现在我想在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 doc:router doc中找到更多详细信息

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读