javascript - Angular JS - Retrieve URL parameters -


what correct angular approach retrieving url parameters?

example: http://example.com/mypage.html?product=1234&region=4&lang=en

thanks

this convert query object

var querydata = url.split('?')[url.split('?').length - 1].split('&').reduce(function(prev, curr){     var fieldname = curr.split('=')[0];      var value = curr.split('=').length > 1 ? curr.split('=')[1] : '';     prev[fieldname] = value;      return prev }, {}); 

and can access them querydata.product, example. not angular, it's solution.

for angular way, can use $location.search() described here http://www.angulartutorial.net/2015/04/get-url-parameter-using-angular-js.html


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -