diff options
author | CNlucius <lukai1@huawei.com> | 2016-09-13 11:40:12 +0800 |
---|---|---|
committer | CNlucius <lukai1@huawei.com> | 2016-09-13 11:41:53 +0800 |
commit | b731e2f1dd0972409b136aebc7b463dd72c9cfad (patch) | |
tree | 5107d7d80c19ad8076c2c97c2b5ef8d1cf3ab903 /framework/src/onos/web/gui/src/main/webapp/_sdh/ng-examples/ch05-03-simple-angular-service.js | |
parent | ee93993458266114c29271a481ef9ce7ce621b2a (diff) |
ONOSFW-171
O/S-SFC-ONOS scenario documentation
Change-Id: I51ae1cf736ea24ab6680f8edca1b2bf5dd598365
Signed-off-by: CNlucius <lukai1@huawei.com>
Diffstat (limited to 'framework/src/onos/web/gui/src/main/webapp/_sdh/ng-examples/ch05-03-simple-angular-service.js')
-rw-r--r-- | framework/src/onos/web/gui/src/main/webapp/_sdh/ng-examples/ch05-03-simple-angular-service.js | 115 |
1 files changed, 0 insertions, 115 deletions
diff --git a/framework/src/onos/web/gui/src/main/webapp/_sdh/ng-examples/ch05-03-simple-angular-service.js b/framework/src/onos/web/gui/src/main/webapp/_sdh/ng-examples/ch05-03-simple-angular-service.js deleted file mode 100644 index 25786bed..00000000 --- a/framework/src/onos/web/gui/src/main/webapp/_sdh/ng-examples/ch05-03-simple-angular-service.js +++ /dev/null @@ -1,115 +0,0 @@ -// ch05-03-simple-angular-service.js - -// this example shows three different ways of defining our own "service"... - -// use 'factory()' for functions/plain objects API -// use 'service()' for JS class object API -// use 'provider()' for configurable service API - - -// this is a service definition -function ItemServiceTwo() { - var items = [ - {id: 0, label: 'Item 0'}, - {id: 1, label: 'Item 1'} - ]; - this.list = function () { - return items; - }; - this.add = function (item) { - items.push(item); - }; -} - -// this is a provider definition -function ItemServiceThree(optItems) { - var items = optItems || []; - - this.list = function () { - return items; - }; - this.add = function (item) { - items.push(item); - } -} - -angular.module('notesApp', []) - - // [provider] define item service as configurable provider - .provider('ItemServiceThree', function () { - var haveDefaultItems = true; - - this.disableDefaultItems = function () { - haveDefaultItems = false; - }; - - // this function gets our dependencies.. - this.$get = [function () { - var optItems = []; - if (haveDefaultItems) { - optItems = [ - {id: 0, label: 'Item 0'}, - {id: 1, label: 'Item 1'} - ]; - } - return new ItemServiceThree(optItems); - }]; - }) - - // [provider] define configuration for provider - .config(['ItemServiceThreeProvider', function (ItemServiceThreeProvider) { - // to see how the provider can change configuration - // change the value of shouldHaveDefaults to true and - // try running the example - var shouldHaveDefaults = false; - - // get configuration from server. - // set shouldHaveDefaults somehow - // assume it magically changes for now - if (!shouldHaveDefaults) { - ItemServiceThreeProvider.disableDefaultItems(); - } - }]) - - // [service] define item service as a JS class - .service('ItemServiceTwo', [ItemServiceTwo]) - - // [factory] define item service factory - .factory('ItemService', [function () { - var items = [ - {id: 0, label: 'Item 0'}, - {id: 1, label: 'Item 1'} - ]; - return { - list: function () { - return items; - }, - add: function (item) { - items.push(item); - } - }; - }]) - - // ====================================================================== - // define controllers... - .controller('MainCtrl', [function () { - var self = this; - self.tab = 'first'; - self.open = function (tab) { - self.tab = tab; - }; - }]) - - .controller('SubCtrl', ['ItemService', function (ItemService) { - var self = this; - self.list = function () { - return ItemService.list(); - }; - self.add = function () { - var n = self.list().length; - ItemService.add({ - id: n, - label: 'Item ' + n - }); - }; - }]); |