0

I can't get the header component to register as a module.

I'm stuck, trying to add a new module. I'm using the gulp-angular-scaffold. When running Unit tests (Jasmine), the 'header' module is not defined.

It seems like I'm missing a module declaration, but I'm not sure of where or why?

Thanks in advance

folder structure snapshot:

├──  app/
│   │   ├──  components/
│   │   │   └──  header/
│   │   │   │   ├──  header.controller.js
|   |   |   |   ├──  header.directive.js
|   |   |   |   ├──  header.spec.js
|   |   |   |   ├──  header.js
|   |   |   |   ├──  header.less
│   │   │   │   └──  header.html
│   │   ├──  main/
│   │   │   ├──  main.controller.js
│   │   │   ├──  main.controller.spec.js
│   │   │   └──  main.html
│   │   └──  index.js

index.js:(loads the base/only successful module)

angular.module('styleguide', ['ngSanitize', 'ui.router', 'ui.bootstrap'])
    .controller('MainCtrl', MainCtrl)

header.js:

'use strict';

import HeaderCtrl from 'header.controller.js';

import HeaderNav from 'header.directive.js';

angular.module('header', ['styleguide'])
    .controller('HeaderCtrl', HeaderCtrl)
    .directive('HeaderDir', HeaderNav)
    .config();

header.controller.js

'use strict';

class HeaderCtrl {
  constructor ($scope) {
    $scope.Project = 'header.controller';
  }
}

HeaderCtrl.$inject = ['$scope'];

export default HeaderCtrl;

header.directive.js

'use strict';

class HeaderNav {

  constructor(){
      return {
        templateUrl: '../components/header/header.html'
      };
  }

}

export default HeaderNav;
2
  • What do header.controller.js and header.directive.js look like? Are there any syntax errors in those files? Commented Jun 2, 2015 at 20:18
  • @Tom I added the directive and controller to the post, JSHint isn't complaining about anything in the files and nothing stands out immediately to me. Commented Jun 3, 2015 at 17:59

1 Answer 1

1

You need to add the module in your index file - index.js :

angular.module('styleguide', ['ngSanitize', 'ui.router', 'ui.bootstrap', 'header'])
    .controller('MainCtrl', MainCtrl)

PS: ... unless that's not what you want ?

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

2 Comments

When I add the module that way I'm getting this error: Error: [$injector:modulerr] Failed to instantiate module header due to: Error: [ng:areq] Argument 'fn' is not a function, got undefined
I think its how I wrote the directive, my es6 skills are to blame there

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.