angularjs - access url parameters in controller

531 Views Asked by At

I am trying to access url params in my controller:

I found this example, but I get an error that I think is related to loading the relevant modules.

app.controller('WidgetCtrl', ['$scope', '$routeParams', function ($scope, $routeParams, $http) {
    var param1 = $routeParams.param1;
    var param2 = $routeParams.param2;

    var vm = $scope;

    vm.data = "test";

}]);

Error:

Uncaught Error: [$injector:modulerr]

In my html I have:

    <script src=".../angular-1.2.21/angular.min.js"></script>
    <script src=".../angular-1.2.21/angular-route.min.js"></script>

What is the proper wat to access the url params and use them in the controller? which modules I need to load?

1

There are 1 best solutions below

3
On

From the looks of it, you're not injecting $http, so it should be:

app.controller('WidgetCtrl', ['$scope', '$routeParams', '$http', function ($scope, $routeParams, $http) {

That should get rid of that error.