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 111<br />

Ok, FFS, enough with the theory back ‘n forthing I want to see some codez plz. Ok, ok, I hear you;<br />

what were going to do now is implement the CRUD parts of our TODO application. However, since<br />

I showed you in baby steps the few mains parts of AngularJS, now we’re going to tackle this like big<br />

boys/gals and I’ll give you the exact full code which you have to put in each of the files and then I’ll<br />

comment their crucial parts.<br />

Model me nicely<br />

In the app/models folder of your Express.js app make a new file called todo.server.model.js with<br />

the following full content that will be used for ever and ever:<br />

1 var mongoose = require('mongoose'),<br />

2 Schema = mongoose.Schema;<br />

3<br />

4 var TodoSchema = new Schema({<br />

5 created: {<br />

6 type: Date,<br />

7 default: Date.now<br />

8 },<br />

9 title: {<br />

10 type: String,<br />

11 default: '',<br />

12 trim: true,<br />

13 required: "Title can't be blank"<br />

14 },<br />

15 comment: {<br />

16 type: String,<br />

17 default: '',<br />

18 trim: true<br />

19 },<br />

20 creator: {<br />

21 type: Schema.ObjectId,<br />

22 ref: 'User'<br />

23 },<br />

24 completed: {<br />

25 type: Boolean,<br />

26 default: false<br />

27 }<br />

28 });<br />

29 mongoose.model('Todo', TodoSchema);

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

Saved successfully!

Ooh no, something went wrong!