javascript - AngularJS: GET parameter via $routeParams remains undefined -
using angularjs (v1.3.8) try read parameter url looks this: http://www.foo.com/whatever1?keyword=bla
using following code, keyword 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 placed exactly??):
myapp.config(['$routeprovider', function($routeprovider) { $routeprovider. when('/whatever1/:keyword', { controller: 'mycontroller' }); }]);
Comments
Post a Comment