New to Angular here. I come from the background of PHP and ASP, where the way to read the parameters is as follows:
<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>
(This is not complete code, but you get the idea - very simple)
I have never done parsing requests on the client side before. What is the correct method? I already asked a question in the past, but I have no answers. Google search does not help.
My URL usually has the form: example.com?foo=123&bar=456
Is the above syntax not supported these days? Should I do something like: example.com/foo/123/bar/345?
I want to change the structure of the url for something that works with Angular, but need to point in the right direction. For example, I heard about ngRoute, but I have no idea where to start. Is this the right approach?
In the past, I asked a question, but it didn’t help me, so I rewrite it with more information to make it more understandable.
Thanks for any pointers.
Edit - using $ location
Notice, I tried using $ location, but for me it was unsuccessful. See the following 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); }
Note. I read something about setting up $ locationProvider.html5Mode (true) to get this request processing style to work; however, I was not successful either.