搜索网址参数角JS

编程入门 行业动态 更新时间:2024-10-25 04:26:46
本文介绍了搜索网址参数角JS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

说我有这样的网址:

www.mysite?account=23&token=asdu756sdg65sdf

现在,我需要单独使用角JS 访问这些URL的参数。

Now, I need to access those URL parameters individually using Angular JS.

我试过使用 location.search 我的控制器内的:

I've tried using location.search inside my controller:

console.log(location.search);

这很好地返回完整的查询字符串:

Which nicely returns the full query string:

?account=23&token=asdu756sdg65sdf

但似乎返回一个字符串,而不是一个对象。有一种简单的方法来访问字符串中的个人ID和价值?

But it seems to return a string, not an object. Is there an easy way to access the individual ids and values in the string?

我也试过:

console.log($location.search());

这似乎返回一个空的对象。

Which seems to return an empty object.

推荐答案

与尝试

var account = ($location.search()).account;

但是URL应该像/#!/?帐号= 1

but the url should be like /#!/?account=1

更多推荐

搜索网址参数角JS

本文发布于:2023-11-28 19:31:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1643680.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:参数   网址   JS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!