From 3ed3ee19d7356a00b5c6d0534d547b73a73053a1 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Tue, 4 Nov 2014 16:13:49 -0800 Subject: [PATCH] [Example] Add example of service registration Add an example of registering a plain service with Angular. WTD-518. --- example/builtins/bundle.json | 8 ++++++-- example/builtins/src/ExampleController.js | 4 ++-- example/builtins/src/ExampleService.js | 25 +++++++++++++++++++++++ 3 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 example/builtins/src/ExampleService.js diff --git a/example/builtins/bundle.json b/example/builtins/bundle.json index c8dfc9a4ce..c047e3f282 100644 --- a/example/builtins/bundle.json +++ b/example/builtins/bundle.json @@ -1,12 +1,13 @@ { "name": "Angular Built-ins Example", "description": "Example showing how to declare extensions with built-in support from Angular.", + "sources": "src", "extensions": { "controllers": [ { "key": "ExampleController", "implementation": "ExampleController.js", - "depends": [ "$scope" ] + "depends": [ "$scope", "exampleService" ] } ], "directives": [ @@ -21,7 +22,10 @@ } ], "services": [ - + { + "key": "exampleService", + "implementation": "ExampleService.js" + } ] } } \ No newline at end of file diff --git a/example/builtins/src/ExampleController.js b/example/builtins/src/ExampleController.js index 57defc0eaf..4e56779d8f 100644 --- a/example/builtins/src/ExampleController.js +++ b/example/builtins/src/ExampleController.js @@ -12,8 +12,8 @@ define( * * @constructor */ - function ExampleController($scope) { - $scope.phrase = "I am a controller."; + function ExampleController($scope, exampleService) { + $scope.phrase = exampleService.getMessage(); } return ExampleController; diff --git a/example/builtins/src/ExampleService.js b/example/builtins/src/ExampleService.js new file mode 100644 index 0000000000..e580a53fcd --- /dev/null +++ b/example/builtins/src/ExampleService.js @@ -0,0 +1,25 @@ +/*global define,Promise*/ + +/** + * Module defining ExampleService. Created by vwoeltje on 11/4/14. + */ +define( + [], + function () { + "use strict"; + + /** + * + * @constructor + */ + function ExampleService() { + return { + getMessage: function () { + return "I heard this from a service"; + } + }; + } + + return ExampleService; + } +); \ No newline at end of file