After getting yeoman installed and creating the first project it is easy to add controllers to the project. Adding controllers is done by running the yo angular:controller newCtrl command in the terminal. (The new controller will be named 'new.js', the 'Ctrl' portion remains in the code, but all the files will be shortened to just 'new.js'.) This creates two files. the first file is the controller and it is located in app/scripts/controller. The second file is the unit test and it is located at test/spec/controllers. When the yo command completes it also adds the controller to index.html, specifically to the last build group specified. This is handy because the new controller will be combined and minified with the rest of the scripts, when you run grunt build.
- How to add a controller to an angular app with yeoman:
-
cd projectRoot -
yo angular:controller newCtrl - Edit app/scripts/controllers/new.js
- Edit test/spec/controllers/new.js
- Check app/index.html to make sure new.js is included with the correct minify group.
-
Run the test and build with
grunt testandgrunt build.