3

I am trying to inject a number of dependencies into a controller as part of a code refactoring process inline with John Papa's Style Guide. Right now, our controller looks like this:

.controller('alerting-settings.mainController', [
    '$scope',
    '$timeout',
    '$location',    
    '$document',
    '$window',

    function($scope,
             $timeout,
             $location,
             $document,
             $window) {

According to John Papa, it should be done more like this:

/* recommended */
angular
    .module('app')
    .controller('DashboardController', DashboardController);

DashboardController.$inject = ['$location', '$routeParams', 'common', 'dataservice'];

function DashboardController($location, $routeParams, common, dataservice) {
}

So what happens when I refactor? I end up with this:

angular.module('app.alerting-settings')

.controller('alerting-settings.mainController', alerting-settings.mainController);

    alerting-settings.mainController.$inject = [
    '$scope',
    '$timeout',
    '$location',    
    '$document',
    '$window'],

Problem is that I get console errors now:

enter image description here

What am I doing wrong?

2
  • Place the $inject after the Controller function. Commented Mar 29, 2016 at 9:24
  • I just did that but I still get "senses-lib.js:70 Uncaught Error: [$injector:nomod] Module 'app.alerting-settings' is not available!" Commented Mar 29, 2016 at 9:35

1 Answer 1

3

You need to rename alerting-settings by alertingSettings everywhere.

You can use use "-" in file name but never in controller/service names because they are "functions" and in javascript you cant have a dash in function name

--> function alerting-settings() is not a valid function name.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.