Best way to parse a query string with AngularJS without using html5mode

Viewed 30314

What's the best way to parse a query string in Angular without using html5mode? (Not using html5mode because we need to support older browsers)

I get the same undefined results whether or not I use a hash:

http://localhost/test?param1=abc&param2=def
http://localhost/test#/param1=abc&param2=def

$routeParams and $location.search() both return undefined:

var app = angular.module('plunker', ["ngRoute"]);

app.controller('MainCtrl', ["$scope", "$routeParams", "$location",
  function($scope, $routeParams, $location) {

  console.log($routeParams, $routeParams.abc); //undefined, undefined
  console.log($location.search(), $location.search().abc); //undefined, undefined

}]);

I can parse the window.location.search myself, but I'm hoping there is a better way to do it in Angular.

Plnkr: http://plnkr.co/edit/alBGFAkfqncVyK7iv8Ia?p=preview

I've read this post and haven't found a solution. I must be missing something. Thanks for the help.

1 Answers
Related