Using AngularJS (v1.3.8) I try to read a GET parameter from a URL which looks like this: http://www.foo.com/whatever1?keyword=bla
Using the following code, keyword for whatever reason remains undefined:
HTML:
<!doctype html>
<html ng-app="myApp">
<head>
<title>test</title>
<script src="/js/angular.min.js"></script>
<script src="/js/angular-route.min.js"></script>
<script src="/js/myangularscript.js"></script>
</head>
<body ng-controller="myController">
[...]
</body>
</html>
Javascript (myangularscript.js):
myApp = angular.module('myApp',['ngRoute']);
myApp.controller('myController', function ($scope,$http,$routeParams,$location) {
alert($routeParams.keyword); //undefined
alert($location.search().keyword); //undefined
});
Added route definition (has to be placed where exactly??):
myApp.config(['$routeProvider',
function($routeProvider) {
$routeProvider.
when('/whatever1/:keyword', {
controller: 'myController'
});
}]);