javascript - Angular JS - Retrieve URL parameters -
what correct angular approach retrieving url parameters?
example: http://example.com/mypage.html?product=1234®ion=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
Post a Comment