Simon Hunt | c022775 | 2014-12-11 16:46:57 -0800 | [diff] [blame] | 1 | // ch05-01-need-for-service-app.js |
| 2 | |
| 3 | angular.module('notesApp', []) |
| 4 | .controller('MainCtrl', [function () { |
| 5 | var self = this; |
| 6 | self.tab = 'first'; |
| 7 | self.open = function (tab) { |
| 8 | self.tab = tab; |
| 9 | } |
| 10 | }]) |
| 11 | .controller('SubCtrl', [function () { |
| 12 | var self = this; |
| 13 | self.list = [ |
| 14 | {id: 0, label: 'Item 0'}, |
| 15 | {id: 1, label: 'Item 1'} |
| 16 | ]; |
| 17 | |
| 18 | self.add = function () { |
| 19 | var n = self.list.length; |
| 20 | self.list.push({ |
| 21 | id: n, |
| 22 | label: 'Item ' + n |
| 23 | }); |
| 24 | } |
| 25 | }]); |
| 26 | |
| 27 | /* |
| 28 | NOTE: When we use controllers, they are instances that get created and |
| 29 | destroyed as we navigate across the application. Any state they |
| 30 | hold is temporary at best, and cannot be communicated to other |
| 31 | controllers. |
| 32 | |
| 33 | That's why we'd use "services" instead. |
| 34 | */ |