#Angular ControllerAs InClass


Navigate to your repository and:

mkdir Week10-ControllerAs
cd Week10-ControllerAs
yo angular
yo mocha


Create Unit Tests

In test/spec/controllers/ Rename:

  • about.js => AboutSpec.js
  • main.js => MainSpec.js

Add two test suites to test/spec/controllers:

  • Marie.js
  • Pierre.js

Create four failing tests:

  • In’shows that we can get the description from main’
  • ‘shows that we can get the description from about’
  • ‘shows that we can get the description from Marie’
  • ‘shows that we can get the description from Pierre’

Chai and Spec are Optional

At the top of your tests:

var expect = chai.expect;

In the files section of karma.conf.js:



npm install karma-spec-reporter --save-dev


exclude: [],

reporters: ['spec'],

In karm.conf.js:

plugins: [

In Gruntfile.js: singleRun: false; about line 387.

Optional mocha

Don’t do this in class.

Install karma-mocha: npm install karma-mocha –save-dev

In karma.conf.js: frameworks: [‘mocha’],

In karm.conf.js:

plugins: [


Create four ControllerAs entries in app.js, adding new objects as necessary:

  • mainController
  • aboutController
  • marieController
  • pierreController

Instantiate controllerAs in about.js and main.js and other files:

var mainController = this;
mainController.description = "This is the main etc...';

Keep working until all your tests pass.

Make sure the app itself works on port 30025. Don’t forget to check for routes in app.js and for loading the new controller files (marie, pierre, CurieFactory) in index.html.


Create a CurieFactory.js file. Create a function object in the Factory. Set it up just like the modular pattern, but without the outer and closing parens: ()(). A bit like this, perhaps:

function CurieFactory() {

CurieFactory.prototype.getMarie = function() {
   return {
        description: 'Marie Curie created the...',
        born: 1867,


return new CurieFactory();

In your Marie Controller


Include a mixin that contains a menu that includes dropdowns.