美文网首页前端
angular里route中参数的使用

angular里route中参数的使用

作者: avery1 | 来源:发表于2019-01-02 15:03 被阅读149次

angular的route中包含了很多的信息,我们可以拿来使用。

route route对象

我们来看下面的概念

什么是Subject?在RxJS中,Subject是一类特殊的Observable,它可以向多个Observer多路推送数值。普通的Observable并不具备多路推送的能力(每一个Observer都有自己独立的执行环境),而Subject可以共享一个执行环境。

BehaviorSubject 是Subject的一个衍生类,具有“最新的值”的概念。它总是保存最近向数据消费者发送的值,当一个Observer订阅后,它会即刻从 BehaviorSubject 收到“最新的值”。

所以BehaviorSubject其实就是一个Observable对象。

我们来看route里的BehaviorSubject。

给出URL:http://localhost:4200/solution/11967?name=qw#gate

1.data

执行this.route.data.subscribe(i => console.log(i));

{title: "Solution Edit"}

2.fragment

就是#后面的值,我们可以用来处理锚点的问题。

执行this.route.fragment.subscribe(i => console.log(i));

gate

锚点处理

private anchor: string;

ngOnInit() {

        this.router.fragment.subscribe( i => {

                this.anchor = i;   // 找到锚点字符串

        })

}

然后利用scrollToView即可。

3.params

执行this.route.params.subscribe(i => console.log(i));

{id: "11967"}

4.queryParams

执行this.route.queryParams.subscribe(i => console.log(i));


5.url

执行this.route.url.subscribe(i => console.log(i));

{name: "qw", age: "12"}

相关文章

  • angular里route中参数的使用

    angular的route中包含了很多的信息,我们可以拿来使用。 我们来看下面的概念 什么是Subject?在Rx...

  • Angular Route导航

    Angular Route导航 路由基础知识 路由相关对象介绍 新建路由项目 使用angular-cli新建项目。...

  • vue常用的路由间传参

    使用$route 使用 props将组件与路由解耦 方式一:使用$route 此方法传递参数不在URL路径拼接显示...

  • 从Url中获取参数

    vue中的route可以从Url中获取参数,比如:this.$route.query.id但是这只是在route有...

  • SAP Spartacus Set Active BaseSit

    从Angular route event url里得到base site: navigation 触发方式:imp...

  • 基于OC的基础Router实现

    Route 路由实现功能 使用 api导航 服务导航 总结 使用 解析参数 传入参数调用 路由规则 scheme:...

  • angular.copy() 深拷贝

    使用方法: angular.copy(source, [destination]); 参数: 参数名称参数类型描述...

  • 如何使用ui-router?

    如何使用ui-router? 一.背景介绍 angular路由 路由(route),几乎所有的MVC(VM)框架都...

  • AngularJS-路由

    1、首先我们要引进angular.js和angular-route.js文件 2、然后我们要在html中创建锚点和...

  • AngularJS route路由

    route 通过Angular构建的单页面程序,用同一个url访问要展示不一样的效果可以使用到route,先到项目...

网友评论

    本文标题:angular里route中参数的使用

    本文链接:https://www.haomeiwen.com/subject/slyzlqtx.html