Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Building a MEAN Application Going MEAN with Angular Setting Up webpack

Michael Randall
PLUS
Michael Randall
Courses Plus Student 10,643 Points

Where are the teachers notes describing how to update the JS files with the angular reference?

Towards the end of the video Huston showed how to add "var angular = require('angular');" to main.js. He said that we could update the other js files, but didn't specify which ones. He said that there would be some kind of guidance listed in the teacher's notes section. Is there a specific section of the webpack documentation that we should look at to find the information?

3 Answers

I'm not 100% sure, but I think, in all your js file you need to require Angular. Then, in your main file, where you created the angular Module, you just require all your js file. Like Housten did with the main-Controller..

Derek Shanks
Derek Shanks
9,543 Points

Yeah, they kinda missed the boat on introducing Webpack without assisting us in setting it up properly. There is supposed to be a blog post 'Setting up Angular with Webpack'. That isn't available when you click the link.

At the top of all of your Angular files ( /controllers/main.js , /controllers/todo.js , /directives/todo.js, /services/data.js ) below the 'use strict' statement : You need to add the following.

var angular = require('angular');

Once those have been updated, your app.js file should look like this.

'use strict';

var angular = require('angular');

angular.module('todoListApp', []);

require('./scripts/controllers/main.js');
require('./scripts/controllers/todo.js');
require('./scripts/directives/todo.js');
require('./scripts/services/data.js');
Michael Randall
Michael Randall
Courses Plus Student 10,643 Points

I had to watch the video again to understand what was happening, but after that I figured I had to require angular in all the files in the controllers, directives, and services directories, basically 3 additional files to the one Huston modified. I also had to require those files in the app.js file. The response from Derek Shanks describes this perfectly. If you run webpack each time you add a new require statement to the app.js file and then add the require angular statement the file, you can look at your todo.bundles.js file and you will see that the new reference has been added to the file.

Hans Hovanitz
Hans Hovanitz
923 Points

Thanks for this, was very helpful.

@Derek Shanks -- You notes answered my question, thank you.