提取URL查询参数与AngularUI [英] Extract URL query parameters with AngularUI

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

问题描述

我使用AngularUI库,并希望从URL中提取查询参数与
(样品网址:#\\书\\:?的categoryID出版商= XYZ #\\书\\值出版商= XYZ ))。

I am using AngularUI library and want to extract the query parameters with from a URL (sample URL: #\books\:categoryID?publisher=xyz (#\books\value?publisher=xyz)).

$ stateParams 提取数据为 {的categoryId:值出版商= XYZ} ,但我需要得到为 {的categoryId:值,出版:XYZ}

The $stateParams extracts the data as {categoryId:value?publisher=xyz} but I need to get it as {categoryId:"value", publisher:"xyz"}.

在此先感谢

推荐答案

UI路由器具有传递参数作为查询字符串PARAMS直接支持。有一个文档

Angular ui-router has direct support for passing parameters as a query string params. There is a doc

  • URL Parameters - Query Parameters

有是一个例子,在此状态下定义的链接:

There is a link to an example, using this state definition:

  $stateProvider
    .state('books', {
      url : '/books/:categoryID?publisher',
      template: '<div> This is a state def: '+
      '<pre>{{toNiceJson(state)}}</pre>' +
      ' These are params sent to this state:' +
      '<pre>{{toNiceJson(params)}}</pre>'+ 
      ' </div>',
      controller: 'urlParamsCtrl', 
    }) 

而这些可能是链接到那个状态

And these could be links to get to that state

<a href="#/books/value?publisher=xyz">...
<a href="#/books/other?publisher=unknown%20publisher">...
<a ui-sref="books({categoryID:'value', publisher:'xyz'})">...
<a ui-sref="books({categoryID:'other', publisher:'unknown publisher'})">...

查看更多 rel=\"nofollow\">

See more here

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

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