GUI - Angular:: More sample code; this time, services.
Change-Id: I91422074870722e6a58b096d411e64b5a46c7cc0
diff --git a/web/gui/src/main/webapp/_sdh/ng-examples/ch05-01-need-for-service-app.js b/web/gui/src/main/webapp/_sdh/ng-examples/ch05-01-need-for-service-app.js
new file mode 100644
index 0000000..4e25b0b
--- /dev/null
+++ b/web/gui/src/main/webapp/_sdh/ng-examples/ch05-01-need-for-service-app.js
@@ -0,0 +1,34 @@
+// ch05-01-need-for-service-app.js
+
+angular.module('notesApp', [])
+ .controller('MainCtrl', [function () {
+ var self = this;
+ self.tab = 'first';
+ self.open = function (tab) {
+ self.tab = tab;
+ }
+ }])
+ .controller('SubCtrl', [function () {
+ var self = this;
+ self.list = [
+ {id: 0, label: 'Item 0'},
+ {id: 1, label: 'Item 1'}
+ ];
+
+ self.add = function () {
+ var n = self.list.length;
+ self.list.push({
+ id: n,
+ label: 'Item ' + n
+ });
+ }
+ }]);
+
+/*
+ NOTE: When we use controllers, they are instances that get created and
+ destroyed as we navigate across the application. Any state they
+ hold is temporary at best, and cannot be communicated to other
+ controllers.
+
+ That's why we'd use "services" instead.
+ */