最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Angular js - get url query params when url has # hash - Stack Overflow

programmeradmin5浏览0评论

I have an url like this:

site.co/asd#antani?id=9

How do i get id value from this url dynamically and get the new value when it changes?

i tryed :

console.log($routeParams); and i got Object {} in console

thanks

I have an url like this:

site.co/asd#antani?id=9

How do i get id value from this url dynamically and get the new value when it changes?

i tryed :

console.log($routeParams); and i got Object {} in console

thanks

Share Improve this question edited Feb 27, 2015 at 0:02 Bennett McElwee 25.8k6 gold badges56 silver badges65 bronze badges asked Apr 5, 2014 at 12:39 Filippo orettiFilippo oretti 49.9k96 gold badges229 silver badges351 bronze badges 3
  • @StarsSky lol you know it :D – Filippo oretti Commented Apr 5, 2014 at 12:41
  • Did you try $location.search(). it should return {id: 9} – Maxim Shoustin Commented Apr 5, 2014 at 12:52
  • @MaximShoustin i'm into a directive when i log $location.search() it's always empty object :( {} – Filippo oretti Commented Apr 5, 2014 at 12:53
Add a ment  | 

5 Answers 5

Reset to default 2

Since I don't know your full Env. I would go to this dirtection:

var s = $location.search('site.co/asd#antani?id=9');

console.log(s.$$search);

Output:

Object {site.co/asd#antani?id: "9"} 

Hope it will help,

OK i think i fixed it and it was to change URL

so to make $routeParams works i needed to call

site./asd?id=9#antani

instead of

site.co/asd#antani?id=9

hope it can help also if i don't like the url in that way :D

big thanks to all and if you have any better solution let me know please !

Got a gist to do that and other useful functions on urls with params ( URL params to object, Test if url Has Params, get Hash without params, and Change url params)

https://gist.github./dazzer13/10470514

You can do this:

var params = urlGetParams(url);

params.id // returns 9

var myURL = "site.co/asd#antani?id=9";
var myURL_id = myURL.split("#")[1];

Assuming this is the actual page you are on, you can use angular $routeParams. Something like this:

var id = $routeParams.id
发布评论

评论列表(0)

  1. 暂无评论