title: Reading URL parameters in AngularJS - A simple way?
body: <p>New to Angular here. I come from a PHP and ASP background, where the way we read parameters is like this:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
      &lt;script type="text/javascript"&gt;
          var foo = &lt;?php echo $_GET['foo']; ?&gt;;
          var bar = &lt;?php echo $_GET['bar']; ?&gt;;
  
          $(document).ready(function() {
              alert('Foo is: ' + foo + ' and bar is: ' + bar);
          });
      &lt;/script&gt;
  &lt;head&gt;
  </code></pre>
  
  <p>(It's not complete code, but you get the idea -- very simple)</p>
  
  <p>I've never done "client-side" query parsing before. What is the correct method? I've posted a question in the past, but I'm not getting any answers. Google searching is not helping either. </p>
  
  <p>My URL is typically is in the form of: example.com?foo=123&amp;bar=456</p>
  
  <p>Is the above syntax not supported these days? Should I be doing something like: example.com/foo/123/bar/345 instead? </p>
  
  <p>I'm willing to change my URL structure for something that works cleanly with Angular, but need to be pointed in the right direction. For example, I've heard of ngRoute, but I have no idea where to even start. Is this the correct approach?</p>
  
  <p>I've posted a question in the past, but didn't get much help, so I'm re-posting this with more information so that it's more clear. </p>
  
  <p>Thanks for any pointers. </p>
  
  <h2>Edit - using $location</h2>
  
  <p>Note, I've tried using $location, but I this has been unsuccessful for me. See code below:</p>
  
  <pre><code>angular.module('myApp')
      .controller('MyController', ['$location', MyController]);
  
  function MyController($location) {
      var params = $location.search();
  
      alert('foo is: ' + params.foo + ' and bar is: ' + params.bar);
  }
  </code></pre>
  
  <p>Note: I've read something about setting $locationProvider.html5Mode(true) in order to get this style of query parsing to work; however, I've been unsuccessful with this too. </p>