juleee
juleee

Reputation: 466

Which dependency is missing in my angular Module?

I defined an angular module and angular keeps complaining about a missing "$routeProvider". I don't understand as i defined the 'ngRoute' as dependency of my module.

My Code:

(function () {
    'use strict';

    var FlightlistController = function () {
      //code comes inside here
    };

    angular.module('flights', ['ngRoute'])

    .config(['$routeProvider', function ($routeProvider) {
        $routeProvider
            .when('/flightslist', {
                controller: 'FlightsController',
                controllerAs: 'flights',
                templateUrl: 'modules/flight/list.view.html'
            })
        }])

    .controller('FlightsController', ['$routeProvider', FlightlistController])

})();

The error i get

Upvotes: 1

Views: 722

Answers (3)

M. Junaid Salaat
M. Junaid Salaat

Reputation: 3783

Please remove the $routeProvider from controller definition.

.controller('FlightsController', ['$routeProvider', FlightlistController])

just use

.controller('FlightsController', FlightlistController);

Hope this helps now.

Upvotes: 1

Ruwantha R.
Ruwantha R.

Reputation: 82

You need to specify the input parameter of the controller (function FlightlistController).

var FlightlistController = function () need to be changed to var FlightlistController = function ($routeProvider)

And as per your error message check have you specify the script reference for ngRoute. if not place it after you add the script reference of angular.

Upvotes: 0

z.a.
z.a.

Reputation: 2777

You forgot to inject it in your controller function as a param

(function () {
    'use strict';

    var FlightlistController = function ($routeProvider) {
      //code comes inside here
    };

    angular.module('flights', ['ngRoute'])

    .config(['$routeProvider', function ($routeProvider) {
        $routeProvider
            .when('/flightslist', {
                controller: 'FlightsController',
                controllerAs: 'flights',
                templateUrl: 'modules/flight/list.view.html'
            })
        }])

    .controller('FlightsController', ['$routeProvider', FlightlistController])

})();

Upvotes: 0

Related Questions