angularjs - Get parameters url angular when run app -


this question has answer here:

is there way params in angularjs 1.4 when app runs, when params come method? ex: http://www.myapp.com/whatever?param1=1234 mean here in app.js file:

var myapplication = angular.module('app', [ui.router,...])         .run(function ($rootscope,$http,....){              var param = // wish read param here } 

if not possible, how can using controller? thanks

if route configured receive parameters can observe $statechangestart

$rootscope.$on('$statechangestart', function (event, tostate, toparams, fromstate, fromparams) { console.log(toparams); } 

if not, there workaround (works :d):

one one

function getparambyname(name, url) {     if (!url) url = window.location.href;     name = name.replace(/[\[\]]/g, "\\$&");     var regex = new regexp("[?&]" + name + "(=([^&#]*)|&|#|$)"),         results = regex.exec(url);     if (!results) return null;     if (!results[2]) return '';     return decodeuricomponent(results[2].replace(/\+/g, " ")); }  getparambyname('param1'); 

or all

function getqueryparams(qs) {     qs = qs.split('+').join(' ');     var params = {},         tokens,         re = /[?&]?([^=]+)=([^&]*)/g;     while (tokens = re.exec(qs)) {         params[decodeuricomponent(tokens[1])] = decodeuricomponent(tokens[2]);     }     return params; }  console.log(getqueryparams(document.location.search)); 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -