New to Angular here. I come from a PHP and ASP background, where the way we read parameters is like this:
<html>
<head>
<script type="text/javascript">
var foo = <?php echo $_GET['foo']; ?>;
var bar = <?php echo $_GET['bar']; ?>;
$(document).ready(function() {
alert('Foo is: ' + foo + ' and bar is: ' + bar);
});
</script>
<head>
(It's not complete code, but you get the idea -- very simple)
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.
My URL is typically is in the form of: example.com?foo=123&bar=456
Is the above syntax not supported these days? Should I be doing something like: example.com/foo/123/bar/345 instead?
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?
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.
Thanks for any pointers.
Edit - using $location
Note, I've tried using $location, but I this has been unsuccessful for me. See code below:
angular.module('myApp')
.controller('MyController', ['$location', MyController]);
function MyController($location) {
var params = $location.search();
alert('foo is: ' + params.foo + ' and bar is: ' + params.bar);
}
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.