如何提取与UI的路由器AngularJS查询参数? [英] How to extract query parameters with ui-router for AngularJS?

查看:151
本文介绍了如何提取与UI的路由器AngularJS查询参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何使用 UI路由器以AngularJS提取查询参数?

How do I extract query parameters using ui-router for AngularJS?

在AngularJS自己的 $位置服务我所做的:

In AngularJS' own $location service I did:

($ location.search())。UID

($location.search()).uid

提取一个URL参数UID。什么是相应的code为UI的路由器?

to extract the parameter uid from a URL. What is the corresponding code for ui-router?

推荐答案

除非你(请参见文档)绑定到查询参数,你不直接通过 $状态 $ stateParams 。使用 $位置服务。

Unless you're binding to the query parameters (see the documentation), you don't access them directly through $state or $stateParams. Use the $location service.

编辑: 文档,如果你想捕捉 $ stateParams ,可以追加一个你的网址,并将其命名每个查询参数,通过分离&安培; ,即 URL:/ foo的酒吧和放大器;巴兹

Per the docs, if you want to capture query parameters in $stateParams, you can append a ? to your url, and name each query parameter, separated by &, i.e. url: "/foo?bar&baz".

这篇关于如何提取与UI的路由器AngularJS查询参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆