18.05.2016 Views

Mittwoch, 18. Mai, 2016

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Finishing Angular TODO application and deploying to production 122<br />

25<br />

26 app.use(flash());<br />

27 app.use(passport.initialize());<br />

28 app.use(passport.session());<br />

29<br />

30 require('../app/routes/index.server.routes.js')(app);<br />

31 require('../app/routes/users.server.routes.js')(app);<br />

32 require('../app/routes/todos.server.routes.js')(app);<br />

33<br />

34 app.use(express.static('./public'));<br />

35<br />

36 return app;<br />

37 };<br />

Angular CRUDe elements of our ever so slightly MEAN TODO app<br />

Wait, didn’t I see this title before?! Yeah, kind of, but this one has Angular in it ;), and no Patrick<br />

Rothfuss reference<br />

The following few steps should feel very familiar (same M.O.²⁰³ as when we were adding the ngRoute<br />

module). Since we designed our Express API in a RESTful²⁰⁴ manner, we can make use of the external<br />

ngResource²⁰⁵ module. First, install ngResource with bower:<br />

1 bower install angular-resource<br />

Next, you need to add this script file in app/views/index.ejs just after the ngRoute inclusion script:<br />

1 <br />

Also, you have to add the ngResource dependency in your main application.js file:<br />

1 var app = angular.module(appName, ['ngResource', 'ngRoute', 'example', 'users']);<br />

MVC structure<br />

In the public folder create a new folder todos and inside it create a new file todos.client.module.js<br />

with the following content:<br />

²⁰³https://en.wikipedia.org/wiki/Modus_operandi<br />

²⁰⁴https://en.wikipedia.org/wiki/Representational_state_transfer<br />

²⁰⁵https://docs.angularjs.org/api/ngResource

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!