diff options
| author | Caitlin Potter | 2014-02-15 20:19:10 -0500 |
|---|---|---|
| committer | Peter Bacon Darwin | 2014-02-16 19:03:45 +0000 |
| commit | f7fad29fd99cabdbb17fa02dc214de2354f93cdf (patch) | |
| tree | 61fc2299fe732d189f85b0afe84e70667bf9fd13 /docs/content/guide/dev_guide.services.injecting_controllers.ngdoc | |
| parent | 896e34689dfe0d66c09627179940a7b3eaac41bc (diff) | |
| download | angular.js-f7fad29fd99cabdbb17fa02dc214de2354f93cdf.tar.bz2 | |
docs(bike-shed-migration): convert guide <doc:...> examples to <example>...
This CL also contains style fixes as the converted scripts caused jshint to complain.
Diffstat (limited to 'docs/content/guide/dev_guide.services.injecting_controllers.ngdoc')
| -rw-r--r-- | docs/content/guide/dev_guide.services.injecting_controllers.ngdoc | 140 |
1 files changed, 71 insertions, 69 deletions
diff --git a/docs/content/guide/dev_guide.services.injecting_controllers.ngdoc b/docs/content/guide/dev_guide.services.injecting_controllers.ngdoc index c06322fd..f3a6dbc9 100644 --- a/docs/content/guide/dev_guide.services.injecting_controllers.ngdoc +++ b/docs/content/guide/dev_guide.services.injecting_controllers.ngdoc @@ -28,45 +28,46 @@ function myController($loc, $log) { myController.$inject = ['$location', '$log']; ``` -<doc:example module="MyServiceModule"> -<doc:source> -<script> -angular. - module('MyServiceModule', []). - factory('notify', ['$window', function(win) { - var msgs = []; - return function(msg) { - msgs.push(msg); - if (msgs.length == 3) { - win.alert(msgs.join("\n")); - msgs = []; - } - }; - }]); - -function myController(scope, notifyService) { - scope.callNotify = function(msg) { - notifyService(msg); - }; -} - -myController.$inject = ['$scope','notify']; -</script> - -<div id="simple" ng-controller="myController"> - <p>Let's try this simple notify service, injected into the controller...</p> - <input ng-init="message='test'" ng-model="message" > - <button ng-click="callNotify(message);">NOTIFY</button> - <p>(you have to click 3 times to see an alert)</p> -</div> -</doc:source> -<doc:protractor> - it('should test service', function() { - expect(element(by.id('simple')).element(by.model('message')).getAttribute('value')) - .toEqual('test'); - }); -</doc:protractor> -</doc:example> +<example module="MyServiceModule"> + <file name="index.html"> + <div id="simple" ng-controller="myController"> + <p>Let's try this simple notify service, injected into the controller...</p> + <input ng-init="message='test'" ng-model="message" > + <button ng-click="callNotify(message);">NOTIFY</button> + <p>(you have to click 3 times to see an alert)</p> + </div> + </file> + + <file name="script.js"> + angular. + module('MyServiceModule', []). + factory('notify', ['$window', function(win) { + var msgs = []; + return function(msg) { + msgs.push(msg); + if (msgs.length == 3) { + win.alert(msgs.join("\n")); + msgs = []; + } + }; + }]); + + function myController(scope, notifyService) { + scope.callNotify = function(msg) { + notifyService(msg); + }; + } + + myController.$inject = ['$scope','notify']; + </file> + + <file name="protractor.js" type="protractor"> + it('should test service', function() { + expect(element(by.id('simple')).element(by.model('message')).getAttribute('value')) + .toEqual('test'); + }); + </file> +</example> ## Implicit Dependency Injection @@ -74,36 +75,37 @@ A new feature of Angular DI allows it to determine the dependency from the name Let's rewrite the above example to show the use of this implicit dependency injection of `$window`, `$scope`, and our `notify` service: -<doc:example module="MyServiceModuleDI"> -<doc:source> -<script> -angular. - module('MyServiceModuleDI', []). - factory('notify', function($window) { - var msgs = []; - return function(msg) { - msgs.push(msg); - if (msgs.length == 3) { - $window.alert(msgs.join("\n")); - msgs = []; - } - }; - }); - -function myController($scope, notify) { - $scope.callNotify = function(msg) { - notify(msg); - }; -} -</script> -<div id="implicit" ng-controller="myController"> - <p>Let's try the notify service, that is implicitly injected into the controller...</p> - <input ng-init="message='test'" ng-model="message"> - <button ng-click="callNotify(message);">NOTIFY</button> - <p>(you have to click 3 times to see an alert)</p> -</div> -</doc:source> -</doc:example> +<example module="MyServiceModuleDI"> + <file name="index.html"> + <div id="implicit" ng-controller="myController"> + <p>Let's try the notify service, that is implicitly injected into the controller...</p> + <input ng-init="message='test'" ng-model="message"> + <button ng-click="callNotify(message);">NOTIFY</button> + <p>(you have to click 3 times to see an alert)</p> + </div> + </file> + + <file name="script.js"> + angular. + module('MyServiceModuleDI', []). + factory('notify', function($window) { + var msgs = []; + return function(msg) { + msgs.push(msg); + if (msgs.length == 3) { + $window.alert(msgs.join("\n")); + msgs = []; + } + }; + }); + + function myController($scope, notify) { + $scope.callNotify = function(msg) { + notify(msg); + }; + } + </file> +</example> However, if you plan to [minify](http://en.wikipedia.org/wiki/Minification_(programming)) your code, your variable names will get renamed in which case you will still need to explicitly specify |
