|
17 | 17 | * Angular internal service to recognize MessageFormat extensions in interpolation expressions.
|
18 | 18 | * For more information, see:
|
19 | 19 | * https://docs.google.com/a/google.com/document/d/1pbtW2yvtmFBikfRrJd8VAsabiFkKezmYZ_PbgdjQOVU/edit
|
| 20 | + * |
| 21 | + * ## Example |
| 22 | + * |
| 23 | + * <example name="ngMessageFormat-example" module="msgFmtExample" deps="angular-messageFormat.min.js"> |
| 24 | + * <file name="index.html"> |
| 25 | + * <div ng-controller="AppController"> |
| 26 | + * <button ng-click="decreaseRecipients()" id="decreaseRecipients">decreaseRecipients</button><br> |
| 27 | + * <span id="message">{{recipients.length, plural, offset:1 |
| 28 | + * =0 {{{sender.name}} gave no gifts (\#=#)} |
| 29 | + * =1 {{{sender.name}} gave one gift to {{recipients[0].name}} (\#=#)} |
| 30 | + * one {{{sender.name}} gave {{recipients[0].name}} and one other person a gift (\#=#)} |
| 31 | + * other {{{sender.name}} gave {{recipients[0].name}} and # other people a gift (\#=#)} |
| 32 | + * }}</span> |
| 33 | + * </div> |
| 34 | + * </file> |
| 35 | + * |
| 36 | + * <file name="script.js"> |
| 37 | + * function Person(name, gender) { |
| 38 | + * this.name = name; |
| 39 | + * this.gender = gender; |
| 40 | + * } |
| 41 | + * |
| 42 | + * var alice = new Person("Alice", "female"), |
| 43 | + * bob = new Person("Bob", "male"), |
| 44 | + * charlie = new Person("Charlie", "male"), |
| 45 | + * harry = new Person("Harry Potter", "male"); |
| 46 | + * |
| 47 | + * angular.module('msgFmtExample', ['ngMessageFormat']) |
| 48 | + * .controller('AppController', ['$scope', function($scope) { |
| 49 | + * $scope.recipients = [alice, bob, charlie]; |
| 50 | + * $scope.sender = harry; |
| 51 | + * $scope.decreaseRecipients = function() { |
| 52 | + * --$scope.recipients.length; |
| 53 | + * }; |
| 54 | + * }]); |
| 55 | + * </file> |
| 56 | + * |
| 57 | + * <file name="protractor.js" type="protractor"> |
| 58 | + * describe('MessageFormat plural', function() { |
| 59 | + * it('should pluralize initial values', function() { |
| 60 | + * var messageElem = element(by.id('message')), decreaseRecipientsBtn = element(by.id('decreaseRecipients')); |
| 61 | + * expect(messageElem.getText()).toEqual('Harry Potter gave Alice and 2 other people a gift (#=2)'); |
| 62 | + * decreaseRecipientsBtn.click(); |
| 63 | + * expect(messageElem.getText()).toEqual('Harry Potter gave Alice and one other person a gift (#=1)'); |
| 64 | + * decreaseRecipientsBtn.click(); |
| 65 | + * expect(messageElem.getText()).toEqual('Harry Potter gave one gift to Alice (#=0)'); |
| 66 | + * decreaseRecipientsBtn.click(); |
| 67 | + * expect(messageElem.getText()).toEqual('Harry Potter gave no gifts (#=-1)'); |
| 68 | + * }); |
| 69 | + * }); |
| 70 | + * </file> |
| 71 | + * </example> |
20 | 72 | */
|
21 | 73 | var $$MessageFormatFactory = ['$parse', '$locale', '$sce', '$exceptionHandler', function $$messageFormat(
|
22 | 74 | $parse, $locale, $sce, $exceptionHandler) {
|
@@ -61,7 +113,7 @@ var $$interpolateDecorator = ['$$messageFormat', '$delegate', function $$interpo
|
61 | 113 | * @name ngMessageFormat
|
62 | 114 | * @description
|
63 | 115 | */
|
64 |
| -var module = angular['module']('ngMessageFormat', ['ng']); |
| 116 | +var module = window['angular']['module']('ngMessageFormat', ['ng']); |
65 | 117 | module['factory']('$$messageFormat', $$MessageFormatFactory);
|
66 | 118 | module['config'](['$provide', function($provide) {
|
67 | 119 | $provide['decorator']('$interpolate', $$interpolateDecorator);
|
|
0 commit comments