Hello, I'm new to Angular and coming from a background in PHP and ASP. In those languages, we typically read parameters 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>
I'm unfamiliar with client-side query parsing and wondering what the correct method is. I've tried Google searches and asked questions before without much success. My URLs usually look like this: example.com?foo=123&bar=456
Is the above syntax outdated? Should I switch to something like example.com/foo/123/bar/345 instead? I'm open to changing my URL structure for better compatibility with Angular, but I need some guidance on where to start. I've heard about ngRoute, but don't know how to begin. Is that the right way to go?
I appreciate any help or pointers you can offer.
Edit - using $location
I've attempted using $location but haven't had much luck. Here's the 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);
}
I've read about setting $locationProvider.html5Mode(true) for this kind of query parsing to work, but I haven't been successful with that either.