diff --git a/build/app/app.component.js b/build/app/app.component.js index 3406c6094..a7c33ff17 100644 --- a/build/app/app.component.js +++ b/build/app/app.component.js @@ -9,7 +9,6 @@ var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var core_1 = require('@angular/core'); -var pdf_viewer_component_1 = require('./../pdf-viewer/pdf-viewer.component'); var AppComponent = (function () { function AppComponent() { this.pdfSrc = './pdf-test.pdf'; @@ -24,8 +23,7 @@ var AppComponent = (function () { core_1.Component({ selector: 'pdf-viewer-app', templateUrl: './app/app.component.html', - styleUrls: ['./app/app.component.css'], - directives: [pdf_viewer_component_1.PdfViewerComponent] + styleUrls: ['./app/app.component.css'] }), __metadata('design:paramtypes', []) ], AppComponent); diff --git a/build/app/app.component.js.map b/build/app/app.component.js.map index 859d4f472..479f7ceb7 100644 --- a/build/app/app.component.js.map +++ b/build/app/app.component.js.map @@ -1 +1 @@ -{"version":3,"sources":["app/app.component.ts"],"names":[],"mappings":";;;;;;;;;;AAGA,qBAA0B,eAAe,CAAC,CAAA;AAC1C,qCAAmC,sCAAsC,CAAC,CAAA;AAU1E;IAAA;QACE,WAAM,GAAW,gBAAgB,CAAC;QAClC,SAAI,GAAW,CAAC,CAAC;QACjB,iBAAY,GAAY,KAAK,CAAC;QAC9B,YAAO,GAAY,IAAI,CAAC;IAK1B,CAAC;IAHC,oCAAa,GAAb,UAAc,MAAM;QAClB,IAAI,CAAC,IAAI,IAAI,MAAM,CAAC;IACtB,CAAC;IAhBH;QAAC,gBAAS,CAAC;YACT,QAAQ,EAAE,gBAAgB;YAC1B,WAAW,EAAE,0BAA0B;YACvC,SAAS,EAAE,CAAC,yBAAyB,CAAC;YACtC,UAAU,EAAE,CAAC,yCAAkB,CAAC;SACjC,CAAC;;oBAAA;IAYF,mBAAC;AAAD,CATA,AASC,IAAA;AATY,oBAAY,eASxB,CAAA","file":"app/app.component.js","sourcesContent":["/**\n * Created by vadimdez on 21/06/16.\n */\nimport { Component } from '@angular/core';\nimport { PdfViewerComponent } from './../pdf-viewer/pdf-viewer.component';\n\n@Component({\n selector: 'pdf-viewer-app',\n templateUrl: './app/app.component.html',\n styleUrls: ['./app/app.component.css'],\n directives: [PdfViewerComponent]\n})\n\n\nexport class AppComponent {\n pdfSrc: string = './pdf-test.pdf';\n page: number = 1;\n originalSize: boolean = false;\n showAll: boolean = true;\n\n incrementPage(amount) {\n this.page += amount;\n }\n}"],"sourceRoot":"/source/"} \ No newline at end of file +{"version":3,"sources":["app/app.component.ts"],"names":[],"mappings":";;;;;;;;;;AAGA,qBAA0B,eAAe,CAAC,CAAA;AAQ1C;IAAA;QACE,WAAM,GAAW,gBAAgB,CAAC;QAClC,SAAI,GAAW,CAAC,CAAC;QACjB,iBAAY,GAAY,KAAK,CAAC;QAC9B,YAAO,GAAY,IAAI,CAAC;IAK1B,CAAC;IAHC,oCAAa,GAAb,UAAc,MAAM;QAClB,IAAI,CAAC,IAAI,IAAI,MAAM,CAAC;IACtB,CAAC;IAdH;QAAC,gBAAS,CAAC;YACT,QAAQ,EAAE,gBAAgB;YAC1B,WAAW,EAAE,0BAA0B;YACvC,SAAS,EAAE,CAAC,yBAAyB,CAAC;SACvC,CAAC;;oBAAA;IAWF,mBAAC;AAAD,CATA,AASC,IAAA;AATY,oBAAY,eASxB,CAAA","file":"app/app.component.js","sourcesContent":["/**\n * Created by vadimdez on 21/06/16.\n */\nimport { Component } from '@angular/core';\n\n@Component({\n selector: 'pdf-viewer-app',\n templateUrl: './app/app.component.html',\n styleUrls: ['./app/app.component.css']\n})\n\nexport class AppComponent {\n pdfSrc: string = './pdf-test.pdf';\n page: number = 1;\n originalSize: boolean = false;\n showAll: boolean = true;\n\n incrementPage(amount) {\n this.page += amount;\n }\n}"],"sourceRoot":"/source/"} \ No newline at end of file diff --git a/build/app/src/app/app.component.js b/build/app/src/app/app.component.js deleted file mode 100644 index 54c663035..000000000 --- a/build/app/src/app/app.component.js +++ /dev/null @@ -1,36 +0,0 @@ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -var __metadata = (this && this.__metadata) || function (k, v) { - if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); -}; -var core_1 = require('@angular/core'); -var pdf_viewer_component_1 = require('./../pdf-viewer/pdf-viewer.component'); -var mdl_1 = require('./mdl'); -var AppComponent = (function () { - function AppComponent() { - this.pdfSrc = './pdf-test.pdf'; - this.page = 1; - this.originalSize = false; - this.showAll = true; - } - AppComponent.prototype.incrementPage = function (amount) { - this.page += amount; - }; - AppComponent = __decorate([ - core_1.Component({ - selector: 'pdf-viewer-app', - templateUrl: './app/app.component.html', - styleUrls: ['./app/app.component.css'], - directives: [mdl_1.MDL, pdf_viewer_component_1.PdfViewerComponent] - }), - __metadata('design:paramtypes', []) - ], AppComponent); - return AppComponent; -}()); -exports.AppComponent = AppComponent; -//# sourceMappingURL=app.component.js.map \ No newline at end of file diff --git a/build/app/src/app/app.component.js.map b/build/app/src/app/app.component.js.map deleted file mode 100644 index 869d1b1ae..000000000 --- a/build/app/src/app/app.component.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"app.component.js","sourceRoot":"","sources":["../../../../src/app/app.component.ts"],"names":[],"mappings":";;;;;;;;;;AAGA,qBAA0B,eAAe,CAAC,CAAA;AAC1C,qCAAmC,sCAAsC,CAAC,CAAA;AAC1E,oBAAoB,OAAO,CAAC,CAAA;AAU5B;IAAA;QACE,WAAM,GAAW,gBAAgB,CAAC;QAClC,SAAI,GAAW,CAAC,CAAC;QACjB,iBAAY,GAAY,KAAK,CAAC;QAC9B,YAAO,GAAY,IAAI,CAAC;IAK1B,CAAC;IAHC,oCAAa,GAAb,UAAc,MAAM;QAClB,IAAI,CAAC,IAAI,IAAI,MAAM,CAAC;IACtB,CAAC;IAhBH;QAAC,gBAAS,CAAC;YACT,QAAQ,EAAE,gBAAgB;YAC1B,WAAW,EAAE,0BAA0B;YACvC,SAAS,EAAE,CAAC,yBAAyB,CAAC;YACtC,UAAU,EAAE,CAAC,SAAG,EAAE,yCAAkB,CAAC;SACtC,CAAC;;oBAAA;IAYF,mBAAC;AAAD,CAAC,AATD,IASC;AATY,oBAAY,eASxB,CAAA"} \ No newline at end of file diff --git a/build/app/src/app/mdl.js b/build/app/src/app/mdl.js deleted file mode 100644 index 1893ca4cd..000000000 --- a/build/app/src/app/mdl.js +++ /dev/null @@ -1,27 +0,0 @@ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -var __metadata = (this && this.__metadata) || function (k, v) { - if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); -}; -var core_1 = require('@angular/core'); -var MDL = (function () { - function MDL() { - } - MDL.prototype.ngAfterViewInit = function () { - componentHandler.upgradeAllRegistered(); - }; - MDL = __decorate([ - core_1.Directive({ - selector: '[mdl]' - }), - __metadata('design:paramtypes', []) - ], MDL); - return MDL; -}()); -exports.MDL = MDL; -//# sourceMappingURL=mdl.js.map \ No newline at end of file diff --git a/build/app/src/app/mdl.js.map b/build/app/src/app/mdl.js.map deleted file mode 100644 index 4c0ddf83f..000000000 --- a/build/app/src/app/mdl.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"mdl.js","sourceRoot":"","sources":["../../../../src/app/mdl.ts"],"names":[],"mappings":";;;;;;;;;;AAGA,qBAAuC,eAAe,CAAC,CAAA;AAMvD;IAAA;IAIA,CAAC;IAHC,6BAAe,GAAf;QACE,gBAAgB,CAAC,oBAAoB,EAAE,CAAC;IAC1C,CAAC;IANH;QAAC,gBAAS,CAAC;YACT,QAAQ,EAAE,OAAO;SAClB,CAAC;;WAAA;IAKF,UAAC;AAAD,CAAC,AAJD,IAIC;AAJY,WAAG,MAIf,CAAA"} \ No newline at end of file diff --git a/build/app/src/main.js b/build/app/src/main.js deleted file mode 100644 index e3536a58b..000000000 --- a/build/app/src/main.js +++ /dev/null @@ -1,29 +0,0 @@ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -var __metadata = (this && this.__metadata) || function (k, v) { - if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); -}; -var core_1 = require('@angular/core'); -var platform_browser_1 = require('@angular/platform-browser'); -var platform_browser_dynamic_1 = require('@angular/platform-browser-dynamic'); -var app_component_1 = require('./app/app.component'); -var AppModule = (function () { - function AppModule() { - } - AppModule = __decorate([ - core_1.NgModule({ - imports: [platform_browser_1.BrowserModule], - declarations: [app_component_1.AppComponent], - bootstrap: [app_component_1.AppComponent] - }), - __metadata('design:paramtypes', []) - ], AppModule); - return AppModule; -}()); -platform_browser_dynamic_1.platformBrowserDynamic().bootstrapModule(AppModule); -//# sourceMappingURL=main.js.map \ No newline at end of file diff --git a/build/app/src/main.js.map b/build/app/src/main.js.map deleted file mode 100644 index ebf9a08a7..000000000 --- a/build/app/src/main.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"main.js","sourceRoot":"","sources":["../../../src/main.ts"],"names":[],"mappings":";;;;;;;;;;AAGA,qBAAyB,eAAe,CAAC,CAAA;AACzC,iCAA8B,2BAA2B,CAAC,CAAA;AAC1D,yCAAuC,mCAAmC,CAAC,CAAA;AAC3E,8BAA6B,qBAAqB,CAAC,CAAA;AAQnD;IAAA;IAAiB,CAAC;IANlB;QAAC,eAAQ,CAAC;YACR,OAAO,EAAE,CAAC,gCAAa,CAAC;YACxB,YAAY,EAAE,CAAC,4BAAY,CAAC;YAC5B,SAAS,EAAE,CAAC,4BAAY,CAAC;SAC1B,CAAC;;iBAAA;IAEe,gBAAC;AAAD,CAAC,AAAlB,IAAkB;AAElB,iDAAsB,EAAE,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC"} \ No newline at end of file diff --git a/build/app/src/pdf-viewer/pdf-viewer.component.js b/build/app/src/pdf-viewer/pdf-viewer.component.js deleted file mode 100644 index a4ecf0858..000000000 --- a/build/app/src/pdf-viewer/pdf-viewer.component.js +++ /dev/null @@ -1,142 +0,0 @@ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -var __metadata = (this && this.__metadata) || function (k, v) { - if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); -}; -var core_1 = require('@angular/core'); -require('pdfjs-dist/build/pdf.combined'); -var PdfViewerComponent = (function () { - function PdfViewerComponent(element) { - this.element = element; - this._showAll = false; - this._originalSize = true; - this._page = 1; - } - Object.defineProperty(PdfViewerComponent.prototype, "src", { - set: function (_src) { - this._src = _src; - this.fn(); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(PdfViewerComponent.prototype, "page", { - set: function (_page) { - _page = parseInt(_page, 10); - if (this._pdf && this.isValidPageNumber(_page)) { - this._page = _page; - this.renderPage(_page); - } - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(PdfViewerComponent.prototype, "originalSize", { - set: function (originalSize) { - this._originalSize = originalSize; - if (this._pdf) { - this.fn(); - } - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(PdfViewerComponent.prototype, "showAll", { - set: function (value) { - this._showAll = value; - if (this._pdf) { - this.fn(); - } - }, - enumerable: true, - configurable: true - }); - PdfViewerComponent.prototype.fn = function () { - var _this = this; - window.PDFJS.getDocument(this._src).then(function (pdf) { - _this._pdf = pdf; - if (!_this.isValidPageNumber(_this._page)) { - _this._page = 1; - } - if (!_this._showAll) { - return _this.renderPage(_this._page); - } - return _this.renderMultiplePages(); - }); - }; - PdfViewerComponent.prototype.renderMultiplePages = function () { - var _this = this; - var container = this.element.nativeElement.querySelector('div'); - var page = 1; - var renderPageFn = function (page) { return function () { return _this.renderPage(page); }; }; - this.removeAllChildNodes(container); - var d = this.renderPage(page++); - for (page; page <= this._pdf.numPages; page++) { - d = d.then(renderPageFn(page)); - } - }; - PdfViewerComponent.prototype.isValidPageNumber = function (page) { - return this._pdf.numPages >= page && page >= 1; - }; - PdfViewerComponent.prototype.renderPage = function (page) { - var _this = this; - return this._pdf.getPage(page).then(function (page) { - var viewport = page.getViewport(1); - var container = _this.element.nativeElement.querySelector('div'); - var canvas = document.createElement('canvas'); - if (!_this._originalSize) { - viewport = page.getViewport(_this.element.nativeElement.offsetWidth / viewport.width); - } - if (!_this._showAll) { - _this.removeAllChildNodes(container); - } - container.appendChild(canvas); - canvas.height = viewport.height; - canvas.width = viewport.width; - page.render({ - canvasContext: canvas.getContext('2d'), - viewport: viewport - }); - }); - }; - PdfViewerComponent.prototype.removeAllChildNodes = function (element) { - while (element.firstChild) { - element.removeChild(element.firstChild); - } - }; - __decorate([ - core_1.Input(), - __metadata('design:type', Object), - __metadata('design:paramtypes', [Object]) - ], PdfViewerComponent.prototype, "src", null); - __decorate([ - core_1.Input(), - __metadata('design:type', Object), - __metadata('design:paramtypes', [Object]) - ], PdfViewerComponent.prototype, "page", null); - __decorate([ - core_1.Input('original-size'), - __metadata('design:type', Boolean), - __metadata('design:paramtypes', [Boolean]) - ], PdfViewerComponent.prototype, "originalSize", null); - __decorate([ - core_1.Input('show-all'), - __metadata('design:type', Boolean), - __metadata('design:paramtypes', [Boolean]) - ], PdfViewerComponent.prototype, "showAll", null); - PdfViewerComponent = __decorate([ - core_1.Component({ - selector: 'pdf-viewer', - template: '
' - }), - __metadata('design:paramtypes', [core_1.ElementRef]) - ], PdfViewerComponent); - return PdfViewerComponent; -}()); -exports.PdfViewerComponent = PdfViewerComponent; -//# sourceMappingURL=pdf-viewer.component.js.map \ No newline at end of file diff --git a/build/app/src/pdf-viewer/pdf-viewer.component.js.map b/build/app/src/pdf-viewer/pdf-viewer.component.js.map deleted file mode 100644 index e8a7675b3..000000000 --- a/build/app/src/pdf-viewer/pdf-viewer.component.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"pdf-viewer.component.js","sourceRoot":"","sources":["../../../../src/pdf-viewer/pdf-viewer.component.ts"],"names":[],"mappings":";;;;;;;;;;AAGA,qBAA6C,eAAe,CAAC,CAAA;AAC7D,QAAO,+BAA+B,CAAC,CAAA;AAOvC;IAOE,4BAAoB,OAAmB;QAAnB,YAAO,GAAP,OAAO,CAAY;QAN/B,aAAQ,GAAY,KAAK,CAAC;QAC1B,kBAAa,GAAY,IAAI,CAAC;QAG9B,UAAK,GAAW,CAAC,CAAC;IAEgB,CAAC;IAG3C,sBAAI,mCAAG;aAAP,UAAQ,IAAI;YACV,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;YAEjB,IAAI,CAAC,EAAE,EAAE,CAAC;QACZ,CAAC;;;OAAA;IAGD,sBAAI,oCAAI;aAAR,UAAS,KAAK;YACZ,KAAK,GAAG,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;YAE5B,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;gBAC/C,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;gBACnB,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;YACzB,CAAC;QACH,CAAC;;;OAAA;IAGD,sBAAI,4CAAY;aAAhB,UAAiB,YAAqB;YACpC,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;YAElC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;gBACd,IAAI,CAAC,EAAE,EAAE,CAAC;YACZ,CAAC;QACH,CAAC;;;OAAA;IAGD,sBAAI,uCAAO;aAAX,UAAY,KAAc;YACxB,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;YAEtB,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;gBACd,IAAI,CAAC,EAAE,EAAE,CAAC;YACZ,CAAC;QACH,CAAC;;;OAAA;IAEO,+BAAE,GAAV;QAAA,iBAcC;QAbO,MAAO,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,UAAC,GAAQ;YACvD,KAAI,CAAC,IAAI,GAAG,GAAG,CAAC;YAEhB,EAAE,CAAC,CAAC,CAAC,KAAI,CAAC,iBAAiB,CAAC,KAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;gBACxC,KAAI,CAAC,KAAK,GAAG,CAAC,CAAC;YACjB,CAAC;YAED,EAAE,CAAC,CAAC,CAAC,KAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;gBACnB,MAAM,CAAC,KAAI,CAAC,UAAU,CAAC,KAAI,CAAC,KAAK,CAAC,CAAC;YACrC,CAAC;YAED,MAAM,CAAC,KAAI,CAAC,mBAAmB,EAAE,CAAC;QACpC,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,gDAAmB,GAA3B;QAAA,iBAYC;QAXC,IAAI,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QAChE,IAAI,IAAI,GAAG,CAAC,CAAC;QACb,IAAM,YAAY,GAAG,UAAC,IAAY,IAAK,OAAA,cAAM,OAAA,KAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAArB,CAAqB,EAA3B,CAA2B,CAAC;QAEnE,IAAI,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC;QAEpC,IAAI,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC;QAEhC,GAAG,CAAC,CAAC,IAAI,EAAE,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,EAAE,EAAE,CAAC;YAC9C,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC;QACjC,CAAC;IACH,CAAC;IAEO,8CAAiB,GAAzB,UAA0B,IAAY;QACpC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,IAAI,IAAI,IAAI,IAAI,IAAI,CAAC,CAAC;IACjD,CAAC;IAEO,uCAAU,GAAlB,UAAmB,IAAY;QAA/B,iBAwBC;QAvBC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,UAAC,IAAS;YAC5C,IAAI,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;YACnC,IAAI,SAAS,GAAG,KAAI,CAAC,OAAO,CAAC,aAAa,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;YAChE,IAAI,MAAM,GAAsB,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;YAEjE,EAAE,CAAC,CAAC,CAAC,KAAI,CAAC,aAAa,CAAC,CAAC,CAAC;gBACxB,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,KAAI,CAAC,OAAO,CAAC,aAAa,CAAC,WAAW,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;YACvF,CAAC;YAED,EAAE,CAAC,CAAC,CAAC,KAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;gBACnB,KAAI,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC;YACtC,CAAC;YAED,SAAS,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;YAE9B,MAAM,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;YAChC,MAAM,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC;YAE9B,IAAI,CAAC,MAAM,CAAC;gBACV,aAAa,EAAE,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC;gBACtC,QAAQ,EAAE,QAAQ;aACnB,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,gDAAmB,GAA3B,UAA4B,OAAoB;QAC9C,OAAO,OAAO,CAAC,UAAU,EAAE,CAAC;YAC1B,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAC1C,CAAC;IACH,CAAC;IAnGD;QAAC,YAAK,EAAE;;;iDAAA;IAOR;QAAC,YAAK,EAAE;;;kDAAA;IAUR;QAAC,YAAK,CAAC,eAAe,CAAC;;;0DAAA;IASvB;QAAC,YAAK,CAAC,UAAU,CAAC;;;qDAAA;IAxCpB;QAAC,gBAAS,CAAC;YACT,QAAQ,EAAE,YAAY;YACtB,QAAQ,EAAE,8CAA8C;SACzD,CAAC;;0BAAA;IA+GF,yBAAC;AAAD,CAAC,AA7GD,IA6GC;AA7GY,0BAAkB,qBA6G9B,CAAA"} \ No newline at end of file diff --git a/build/lib/@angular/common/bundles/common-testing.umd.js b/build/lib/@angular/common/bundles/common-testing.umd.js new file mode 100644 index 000000000..95cd1fa1f --- /dev/null +++ b/build/lib/@angular/common/bundles/common-testing.umd.js @@ -0,0 +1,200 @@ +/** + * @license Angular v2.0.0-rc.6 + * (c) 2010-2016 Google, Inc. https://angular.io/ + * License: MIT + */ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common')) : + typeof define === 'function' && define.amd ? define(['exports', '@angular/core', '@angular/common'], factory) : + (factory((global.ng = global.ng || {}, global.ng.common = global.ng.common || {}, global.ng.common.testing = global.ng.common.testing || {}),global.ng.core,global.ng.common)); +}(this, function (exports,_angular_core,_angular_common) { 'use strict'; + + /** + * A spy for {@link Location} that allows tests to fire simulated location events. + * + * @experimental + */ + var SpyLocation = (function () { + function SpyLocation() { + this.urlChanges = []; + /** @internal */ + this._history = [new LocationState('', '')]; + /** @internal */ + this._historyIndex = 0; + /** @internal */ + this._subject = new _angular_core.EventEmitter(); + /** @internal */ + this._baseHref = ''; + /** @internal */ + this._platformStrategy = null; + } + SpyLocation.prototype.setInitialPath = function (url) { this._history[this._historyIndex].path = url; }; + SpyLocation.prototype.setBaseHref = function (url) { this._baseHref = url; }; + SpyLocation.prototype.path = function () { return this._history[this._historyIndex].path; }; + SpyLocation.prototype.isCurrentPathEqualTo = function (path, query) { + if (query === void 0) { query = ''; } + var givenPath = path.endsWith('/') ? path.substring(0, path.length - 1) : path; + var currPath = this.path().endsWith('/') ? this.path().substring(0, this.path().length - 1) : this.path(); + return currPath == givenPath + (query.length > 0 ? ('?' + query) : ''); + }; + SpyLocation.prototype.simulateUrlPop = function (pathname) { this._subject.emit({ 'url': pathname, 'pop': true }); }; + SpyLocation.prototype.simulateHashChange = function (pathname) { + // Because we don't prevent the native event, the browser will independently update the path + this.setInitialPath(pathname); + this.urlChanges.push('hash: ' + pathname); + this._subject.emit({ 'url': pathname, 'pop': true, 'type': 'hashchange' }); + }; + SpyLocation.prototype.prepareExternalUrl = function (url) { + if (url.length > 0 && !url.startsWith('/')) { + url = '/' + url; + } + return this._baseHref + url; + }; + SpyLocation.prototype.go = function (path, query) { + if (query === void 0) { query = ''; } + path = this.prepareExternalUrl(path); + if (this._historyIndex > 0) { + this._history.splice(this._historyIndex + 1); + } + this._history.push(new LocationState(path, query)); + this._historyIndex = this._history.length - 1; + var locationState = this._history[this._historyIndex - 1]; + if (locationState.path == path && locationState.query == query) { + return; + } + var url = path + (query.length > 0 ? ('?' + query) : ''); + this.urlChanges.push(url); + this._subject.emit({ 'url': url, 'pop': false }); + }; + SpyLocation.prototype.replaceState = function (path, query) { + if (query === void 0) { query = ''; } + path = this.prepareExternalUrl(path); + var history = this._history[this._historyIndex]; + if (history.path == path && history.query == query) { + return; + } + history.path = path; + history.query = query; + var url = path + (query.length > 0 ? ('?' + query) : ''); + this.urlChanges.push('replace: ' + url); + }; + SpyLocation.prototype.forward = function () { + if (this._historyIndex < (this._history.length - 1)) { + this._historyIndex++; + this._subject.emit({ 'url': this.path(), 'pop': true }); + } + }; + SpyLocation.prototype.back = function () { + if (this._historyIndex > 0) { + this._historyIndex--; + this._subject.emit({ 'url': this.path(), 'pop': true }); + } + }; + SpyLocation.prototype.subscribe = function (onNext, onThrow, onReturn) { + if (onThrow === void 0) { onThrow = null; } + if (onReturn === void 0) { onReturn = null; } + return this._subject.subscribe({ next: onNext, error: onThrow, complete: onReturn }); + }; + SpyLocation.prototype.normalize = function (url) { return null; }; + SpyLocation.decorators = [ + { type: _angular_core.Injectable }, + ]; + /** @nocollapse */ + SpyLocation.ctorParameters = []; + return SpyLocation; + }()); + var LocationState = (function () { + function LocationState(path, query) { + this.path = path; + this.query = query; + } + return LocationState; + }()); + + /** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; + /** + * A mock implementation of {@link LocationStrategy} that allows tests to fire simulated + * location events. + * + * @stable + */ + var MockLocationStrategy = (function (_super) { + __extends(MockLocationStrategy, _super); + function MockLocationStrategy() { + _super.call(this); + this.internalBaseHref = '/'; + this.internalPath = '/'; + this.internalTitle = ''; + this.urlChanges = []; + /** @internal */ + this._subject = new _angular_core.EventEmitter(); + } + MockLocationStrategy.prototype.simulatePopState = function (url) { + this.internalPath = url; + this._subject.emit(new _MockPopStateEvent(this.path())); + }; + MockLocationStrategy.prototype.path = function (includeHash) { + if (includeHash === void 0) { includeHash = false; } + return this.internalPath; + }; + MockLocationStrategy.prototype.prepareExternalUrl = function (internal) { + if (internal.startsWith('/') && this.internalBaseHref.endsWith('/')) { + return this.internalBaseHref + internal.substring(1); + } + return this.internalBaseHref + internal; + }; + MockLocationStrategy.prototype.pushState = function (ctx, title, path, query) { + this.internalTitle = title; + var url = path + (query.length > 0 ? ('?' + query) : ''); + this.internalPath = url; + var externalUrl = this.prepareExternalUrl(url); + this.urlChanges.push(externalUrl); + }; + MockLocationStrategy.prototype.replaceState = function (ctx, title, path, query) { + this.internalTitle = title; + var url = path + (query.length > 0 ? ('?' + query) : ''); + this.internalPath = url; + var externalUrl = this.prepareExternalUrl(url); + this.urlChanges.push('replace: ' + externalUrl); + }; + MockLocationStrategy.prototype.onPopState = function (fn) { this._subject.subscribe({ next: fn }); }; + MockLocationStrategy.prototype.getBaseHref = function () { return this.internalBaseHref; }; + MockLocationStrategy.prototype.back = function () { + if (this.urlChanges.length > 0) { + this.urlChanges.pop(); + var nextUrl = this.urlChanges.length > 0 ? this.urlChanges[this.urlChanges.length - 1] : ''; + this.simulatePopState(nextUrl); + } + }; + MockLocationStrategy.prototype.forward = function () { throw 'not implemented'; }; + MockLocationStrategy.decorators = [ + { type: _angular_core.Injectable }, + ]; + /** @nocollapse */ + MockLocationStrategy.ctorParameters = []; + return MockLocationStrategy; + }(_angular_common.LocationStrategy)); + var _MockPopStateEvent = (function () { + function _MockPopStateEvent(newUrl) { + this.newUrl = newUrl; + this.pop = true; + this.type = 'popstate'; + } + return _MockPopStateEvent; + }()); + + exports.SpyLocation = SpyLocation; + exports.MockLocationStrategy = MockLocationStrategy; + +})); diff --git a/build/lib/@angular/common/bundles/common.umd.js b/build/lib/@angular/common/bundles/common.umd.js index f9ec21bda..e6e47d9a2 100644 --- a/build/lib/@angular/common/bundles/common.umd.js +++ b/build/lib/@angular/common/bundles/common.umd.js @@ -1,19 +1,14 @@ /** - * @license Angular v2.0.0-rc.5 + * @license Angular v2.0.0-rc.6 * (c) 2010-2016 Google, Inc. https://angular.io/ * License: MIT */ -var __extends = (this && this.__extends) || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); -}; (function (global, factory) { - typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('rxjs/operator/toPromise'), require('rxjs/Subject'), require('rxjs/Observable'), require('rxjs/observable/PromiseObservable')) : - typeof define === 'function' && define.amd ? define(['exports', '@angular/core', 'rxjs/operator/toPromise', 'rxjs/Subject', 'rxjs/Observable', 'rxjs/observable/PromiseObservable'], factory) : - (factory((global.ng = global.ng || {}, global.ng.common = global.ng.common || {}), global.ng.core, global.Rx.Observable.prototype, global.Rx, global.Rx, global.Rx)); -}(this, function (exports, _angular_core, rxjs_operator_toPromise, rxjs_Subject, rxjs_Observable, rxjs_observable_PromiseObservable) { - 'use strict'; + typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core')) : + typeof define === 'function' && define.amd ? define(['exports', '@angular/core'], factory) : + (factory((global.ng = global.ng || {}, global.ng.common = global.ng.common || {}),global.ng.core)); +}(this, function (exports,_angular_core) { 'use strict'; + /** * @license * Copyright Google Inc. All Rights Reserved. @@ -36,18 +31,18 @@ var __extends = (this && this.__extends) || function (d, b) { } // Need to declare a new variable for global here since TypeScript // exports the original value of the symbol. - var _global = globalScope; + var global$1 = globalScope; function getTypeNameForDebugging(type) { if (type['name']) { return type['name']; } return typeof type; } - var Date = _global.Date; + var Date = global$1.Date; // TODO: remove calls to assert in production environment // Note: Can't just export this and import in in other files // as `assert` is a reserved keyword in Dart - _global.assert = function assert(condition) { + global$1.assert = function assert(condition) { // TODO: to be fixed properly via #2830, noop for now }; function isPresent(obj) { @@ -164,15 +159,6 @@ var __extends = (this && this.__extends) || function (d, b) { }; return StringWrapper; }()); - var NumberParseError = (function (_super) { - __extends(NumberParseError, _super); - function NumberParseError(message) { - _super.call(this); - this.message = message; - } - NumberParseError.prototype.toString = function () { return this.message; }; - return NumberParseError; - }(Error)); var NumberWrapper = (function () { function NumberWrapper() { } @@ -181,7 +167,7 @@ var __extends = (this && this.__extends) || function (d, b) { NumberWrapper.parseIntAutoRadix = function (text) { var result = parseInt(text); if (isNaN(result)) { - throw new NumberParseError('Invalid integer literal when parsing ' + text); + throw new Error('Invalid integer literal when parsing ' + text); } return result; }; @@ -202,7 +188,7 @@ var __extends = (this && this.__extends) || function (d, b) { return result; } } - throw new NumberParseError('Invalid integer literal when parsing ' + text + ' in base ' + radix); + throw new Error('Invalid integer literal when parsing ' + text + ' in base ' + radix); }; // TODO: NaN is a valid literal but is returned by parseFloat to indicate an error. NumberWrapper.parseFloat = function (text) { return parseFloat(text); }; @@ -216,16 +202,9 @@ var __extends = (this && this.__extends) || function (d, b) { NumberWrapper.isInteger = function (value) { return Number.isInteger(value); }; return NumberWrapper; }()); - // JS has NaN !== NaN - function looseIdentical(a, b) { - return a === b || typeof a === 'number' && typeof b === 'number' && isNaN(a) && isNaN(b); - } function normalizeBlank(obj) { return isBlank(obj) ? null : obj; } - function normalizeBool(obj) { - return isBlank(obj) ? false : obj; - } function isJsObject(o) { return o !== null && (typeof o === 'function' || typeof o === 'object'); } @@ -233,10 +212,10 @@ var __extends = (this && this.__extends) || function (d, b) { var Json = (function () { function Json() { } - Json.parse = function (s) { return _global.JSON.parse(s); }; + Json.parse = function (s) { return global$1.JSON.parse(s); }; Json.stringify = function (data) { // Dart doesn't take 3 arguments - return _global.JSON.stringify(data, null, 2); + return global$1.JSON.stringify(data, null, 2); }; return Json; }()); @@ -279,14 +258,224 @@ var __extends = (this && this.__extends) || function (d, b) { } return _symbolIterator; } - function isPrimitive(obj) { - return !isJsObject(obj); - } - function hasConstructor(value, type) { - return value.constructor === type; - } - var Map$1 = _global.Map; - var Set$1 = _global.Set; + + /** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + var __extends$1 = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; + /** + * @stable + */ + var BaseError = (function (_super) { + __extends$1(BaseError, _super); + function BaseError(message) { + // Errors don't use current this, instead they create a new instance. + // We have to do forward all of our api to the nativeInstance. + var nativeError = _super.call(this, message); + this._nativeError = nativeError; + } + Object.defineProperty(BaseError.prototype, "message", { + get: function () { return this._nativeError.message; }, + set: function (message) { this._nativeError.message = message; }, + enumerable: true, + configurable: true + }); + Object.defineProperty(BaseError.prototype, "name", { + get: function () { return this._nativeError.name; }, + enumerable: true, + configurable: true + }); + Object.defineProperty(BaseError.prototype, "stack", { + get: function () { return this._nativeError.stack; }, + set: function (value) { this._nativeError.stack = value; }, + enumerable: true, + configurable: true + }); + BaseError.prototype.toString = function () { return this._nativeError.toString(); }; + return BaseError; + }(Error)); + /** + * @stable + */ + var WrappedError = (function (_super) { + __extends$1(WrappedError, _super); + function WrappedError(message, error) { + _super.call(this, message + " caused by: " + (error instanceof Error ? error.message : error)); + this.originalError = error; + } + Object.defineProperty(WrappedError.prototype, "stack", { + get: function () { + return (this.originalError instanceof Error ? this.originalError : this._nativeError) + .stack; + }, + enumerable: true, + configurable: true + }); + return WrappedError; + }(BaseError)); + + /** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; + var InvalidPipeArgumentError = (function (_super) { + __extends(InvalidPipeArgumentError, _super); + function InvalidPipeArgumentError(type, value) { + _super.call(this, "Invalid argument '" + value + "' for pipe '" + stringify(type) + "'"); + } + return InvalidPipeArgumentError; + }(BaseError)); + + var ObservableStrategy = (function () { + function ObservableStrategy() { + } + ObservableStrategy.prototype.createSubscription = function (async, updateLatestValue) { + return async.subscribe({ next: updateLatestValue, error: function (e) { throw e; } }); + }; + ObservableStrategy.prototype.dispose = function (subscription) { subscription.unsubscribe(); }; + ObservableStrategy.prototype.onDestroy = function (subscription) { subscription.unsubscribe(); }; + return ObservableStrategy; + }()); + var PromiseStrategy = (function () { + function PromiseStrategy() { + } + PromiseStrategy.prototype.createSubscription = function (async, updateLatestValue) { + return async.then(updateLatestValue, function (e) { throw e; }); + }; + PromiseStrategy.prototype.dispose = function (subscription) { }; + PromiseStrategy.prototype.onDestroy = function (subscription) { }; + return PromiseStrategy; + }()); + var _promiseStrategy = new PromiseStrategy(); + var _observableStrategy = new ObservableStrategy(); + // avoid unused import when Promise union types are erased + /** + * The `async` pipe subscribes to an `Observable` or `Promise` and returns the latest value it has + * emitted. + * When a new value is emitted, the `async` pipe marks the component to be checked for changes. + * When the component gets destroyed, the `async` pipe unsubscribes automatically to avoid + * potential memory leaks. + * + * ## Usage + * + * object | async + * + * where `object` is of type `Observable` or of type `Promise`. + * + * ## Examples + * + * This example binds a `Promise` to the view. Clicking the `Resolve` button resolves the + * promise. + * + * {@example core/pipes/ts/async_pipe/async_pipe_example.ts region='AsyncPipePromise'} + * + * It's also possible to use `async` with Observables. The example below binds the `time` Observable + * to the view. Every 500ms, the `time` Observable updates the view with the current time. + * + * {@example core/pipes/ts/async_pipe/async_pipe_example.ts region='AsyncPipeObservable'} + * + * @stable + */ + var AsyncPipe = (function () { + function AsyncPipe(_ref) { + /** @internal */ + this._latestValue = null; + /** @internal */ + this._latestReturnedValue = null; + /** @internal */ + this._subscription = null; + /** @internal */ + this._obj = null; + this._strategy = null; + this._ref = _ref; + } + AsyncPipe.prototype.ngOnDestroy = function () { + if (isPresent(this._subscription)) { + this._dispose(); + } + }; + AsyncPipe.prototype.transform = function (obj) { + if (isBlank(this._obj)) { + if (isPresent(obj)) { + this._subscribe(obj); + } + this._latestReturnedValue = this._latestValue; + return this._latestValue; + } + if (obj !== this._obj) { + this._dispose(); + return this.transform(obj); + } + if (this._latestValue === this._latestReturnedValue) { + return this._latestReturnedValue; + } + else { + this._latestReturnedValue = this._latestValue; + return _angular_core.WrappedValue.wrap(this._latestValue); + } + }; + /** @internal */ + AsyncPipe.prototype._subscribe = function (obj) { + var _this = this; + this._obj = obj; + this._strategy = this._selectStrategy(obj); + this._subscription = this._strategy.createSubscription(obj, function (value) { return _this._updateLatestValue(obj, value); }); + }; + /** @internal */ + AsyncPipe.prototype._selectStrategy = function (obj) { + if (isPromise(obj)) { + return _promiseStrategy; + } + else if (obj.subscribe) { + return _observableStrategy; + } + else { + throw new InvalidPipeArgumentError(AsyncPipe, obj); + } + }; + /** @internal */ + AsyncPipe.prototype._dispose = function () { + this._strategy.dispose(this._subscription); + this._latestValue = null; + this._latestReturnedValue = null; + this._subscription = null; + this._obj = null; + }; + /** @internal */ + AsyncPipe.prototype._updateLatestValue = function (async, value) { + if (async === this._obj) { + this._latestValue = value; + this._ref.markForCheck(); + } + }; + AsyncPipe.decorators = [ + { type: _angular_core.Pipe, args: [{ name: 'async', pure: false },] }, + ]; + /** @nocollapse */ + AsyncPipe.ctorParameters = [ + { type: _angular_core.ChangeDetectorRef, }, + ]; + return AsyncPipe; + }()); + + var Map$1 = global$1.Map; + var Set$1 = global$1.Set; // Safari and Internet Explorer do not support the iterable parameter to the // Map constructor. We work around that by manually adding the items. var createMapFromPairs = (function () { @@ -357,29 +546,6 @@ var __extends = (this && this.__extends) || function (d, b) { return res; }; })(); - var MapWrapper = (function () { - function MapWrapper() { - } - MapWrapper.clone = function (m) { return createMapFromMap(m); }; - MapWrapper.createFromStringMap = function (stringMap) { - var result = new Map$1(); - for (var prop in stringMap) { - result.set(prop, stringMap[prop]); - } - return result; - }; - MapWrapper.toStringMap = function (m) { - var r = {}; - m.forEach(function (v, k) { return r[k] = v; }); - return r; - }; - MapWrapper.createFromPairs = function (pairs) { return createMapFromPairs(pairs); }; - MapWrapper.clearValues = function (m) { _clearValues(m); }; - MapWrapper.iterable = function (m) { return m; }; - MapWrapper.keys = function (m) { return _arrayFromMap(m, false); }; - MapWrapper.values = function (m) { return _arrayFromMap(m, true); }; - return MapWrapper; - }()); /** * Wraps Javascript Objects */ @@ -601,896 +767,36 @@ var __extends = (this && this.__extends) || function (d, b) { }; } })(); - var NgClass = (function () { - function NgClass(_iterableDiffers, _keyValueDiffers, _ngEl, _renderer) { - this._iterableDiffers = _iterableDiffers; - this._keyValueDiffers = _keyValueDiffers; - this._ngEl = _ngEl; - this._renderer = _renderer; - this._initialClasses = []; + + /** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + var NumberFormatStyle; + (function (NumberFormatStyle) { + NumberFormatStyle[NumberFormatStyle["Decimal"] = 0] = "Decimal"; + NumberFormatStyle[NumberFormatStyle["Percent"] = 1] = "Percent"; + NumberFormatStyle[NumberFormatStyle["Currency"] = 2] = "Currency"; + })(NumberFormatStyle || (NumberFormatStyle = {})); + var NumberFormatter = (function () { + function NumberFormatter() { } - Object.defineProperty(NgClass.prototype, "initialClasses", { - set: function (v) { - this._applyInitialClasses(true); - this._initialClasses = isPresent(v) && isString(v) ? v.split(' ') : []; - this._applyInitialClasses(false); - this._applyClasses(this._rawClass, false); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(NgClass.prototype, "ngClass", { - set: function (v) { - this._cleanupClasses(this._rawClass); - if (isString(v)) { - v = v.split(' '); - } - this._rawClass = v; - this._iterableDiffer = null; - this._keyValueDiffer = null; - if (isPresent(v)) { - if (isListLikeIterable(v)) { - this._iterableDiffer = this._iterableDiffers.find(v).create(null); - } - else { - this._keyValueDiffer = this._keyValueDiffers.find(v).create(null); - } - } - }, - enumerable: true, - configurable: true - }); - NgClass.prototype.ngDoCheck = function () { - if (isPresent(this._iterableDiffer)) { - var changes = this._iterableDiffer.diff(this._rawClass); - if (isPresent(changes)) { - this._applyIterableChanges(changes); - } - } - if (isPresent(this._keyValueDiffer)) { - var changes = this._keyValueDiffer.diff(this._rawClass); - if (isPresent(changes)) { - this._applyKeyValueChanges(changes); - } + NumberFormatter.format = function (num, locale, style, _a) { + var _b = _a === void 0 ? {} : _a, minimumIntegerDigits = _b.minimumIntegerDigits, minimumFractionDigits = _b.minimumFractionDigits, maximumFractionDigits = _b.maximumFractionDigits, currency = _b.currency, _c = _b.currencyAsSymbol, currencyAsSymbol = _c === void 0 ? false : _c; + var options = { + minimumIntegerDigits: minimumIntegerDigits, + minimumFractionDigits: minimumFractionDigits, + maximumFractionDigits: maximumFractionDigits, + style: NumberFormatStyle[style].toLowerCase() + }; + if (style == NumberFormatStyle.Currency) { + options.currency = currency; + options.currencyDisplay = currencyAsSymbol ? 'symbol' : 'code'; } - }; - NgClass.prototype._cleanupClasses = function (rawClassVal) { - this._applyClasses(rawClassVal, true); - this._applyInitialClasses(false); - }; - NgClass.prototype._applyKeyValueChanges = function (changes) { - var _this = this; - changes.forEachAddedItem(function (record) { _this._toggleClass(record.key, record.currentValue); }); - changes.forEachChangedItem(function (record) { _this._toggleClass(record.key, record.currentValue); }); - changes.forEachRemovedItem(function (record) { - if (record.previousValue) { - _this._toggleClass(record.key, false); - } - }); - }; - NgClass.prototype._applyIterableChanges = function (changes) { - var _this = this; - changes.forEachAddedItem(function (record) { _this._toggleClass(record.item, true); }); - changes.forEachRemovedItem(function (record) { _this._toggleClass(record.item, false); }); - }; - NgClass.prototype._applyInitialClasses = function (isCleanup) { - var _this = this; - this._initialClasses.forEach(function (className) { return _this._toggleClass(className, !isCleanup); }); - }; - NgClass.prototype._applyClasses = function (rawClassVal, isCleanup) { - var _this = this; - if (isPresent(rawClassVal)) { - if (isArray(rawClassVal)) { - rawClassVal.forEach(function (className) { return _this._toggleClass(className, !isCleanup); }); - } - else if (rawClassVal instanceof Set) { - rawClassVal.forEach(function (className) { return _this._toggleClass(className, !isCleanup); }); - } - else { - StringMapWrapper.forEach(rawClassVal, function (expVal, className) { - if (isPresent(expVal)) - _this._toggleClass(className, !isCleanup); - }); - } - } - }; - NgClass.prototype._toggleClass = function (className, enabled) { - className = className.trim(); - if (className.length > 0) { - if (className.indexOf(' ') > -1) { - var classes = className.split(/\s+/g); - for (var i = 0, len = classes.length; i < len; i++) { - this._renderer.setElementClass(this._ngEl.nativeElement, classes[i], enabled); - } - } - else { - this._renderer.setElementClass(this._ngEl.nativeElement, className, enabled); - } - } - }; - return NgClass; - }()); - /** @nocollapse */ - NgClass.decorators = [ - { type: _angular_core.Directive, args: [{ selector: '[ngClass]' },] }, - ]; - /** @nocollapse */ - NgClass.ctorParameters = [ - { type: _angular_core.IterableDiffers, }, - { type: _angular_core.KeyValueDiffers, }, - { type: _angular_core.ElementRef, }, - { type: _angular_core.Renderer, }, - ]; - /** @nocollapse */ - NgClass.propDecorators = { - 'initialClasses': [{ type: _angular_core.Input, args: ['class',] },], - 'ngClass': [{ type: _angular_core.Input },], - }; - /** - * @stable - */ - var BaseException = (function (_super) { - __extends(BaseException, _super); - function BaseException(message) { - if (message === void 0) { message = '--'; } - _super.call(this, message); - this.message = message; - this.stack = (new Error(message)).stack; - } - BaseException.prototype.toString = function () { return this.message; }; - return BaseException; - }(Error)); - function unimplemented() { - throw new BaseException('unimplemented'); - } - var NgForRow = (function () { - function NgForRow($implicit, index, count) { - this.$implicit = $implicit; - this.index = index; - this.count = count; - } - Object.defineProperty(NgForRow.prototype, "first", { - get: function () { return this.index === 0; }, - enumerable: true, - configurable: true - }); - Object.defineProperty(NgForRow.prototype, "last", { - get: function () { return this.index === this.count - 1; }, - enumerable: true, - configurable: true - }); - Object.defineProperty(NgForRow.prototype, "even", { - get: function () { return this.index % 2 === 0; }, - enumerable: true, - configurable: true - }); - Object.defineProperty(NgForRow.prototype, "odd", { - get: function () { return !this.even; }, - enumerable: true, - configurable: true - }); - return NgForRow; - }()); - var NgFor = (function () { - function NgFor(_viewContainer, _templateRef, _iterableDiffers, _cdr) { - this._viewContainer = _viewContainer; - this._templateRef = _templateRef; - this._iterableDiffers = _iterableDiffers; - this._cdr = _cdr; - } - Object.defineProperty(NgFor.prototype, "ngForTemplate", { - set: function (value) { - if (isPresent(value)) { - this._templateRef = value; - } - }, - enumerable: true, - configurable: true - }); - NgFor.prototype.ngOnChanges = function (changes) { - if ('ngForOf' in changes) { - // React on ngForOf changes only once all inputs have been initialized - var value = changes['ngForOf'].currentValue; - if (isBlank(this._differ) && isPresent(value)) { - try { - this._differ = this._iterableDiffers.find(value).create(this._cdr, this.ngForTrackBy); - } - catch (e) { - throw new BaseException("Cannot find a differ supporting object '" + value + "' of type '" + getTypeNameForDebugging(value) + "'. NgFor only supports binding to Iterables such as Arrays."); - } - } - } - }; - NgFor.prototype.ngDoCheck = function () { - if (isPresent(this._differ)) { - var changes = this._differ.diff(this.ngForOf); - if (isPresent(changes)) - this._applyChanges(changes); - } - }; - NgFor.prototype._applyChanges = function (changes) { - var _this = this; - var insertTuples = []; - changes.forEachOperation(function (item, adjustedPreviousIndex, currentIndex) { - if (item.previousIndex == null) { - var view = _this._viewContainer.createEmbeddedView(_this._templateRef, new NgForRow(null, null, null), currentIndex); - var tuple = new RecordViewTuple(item, view); - insertTuples.push(tuple); - } - else if (currentIndex == null) { - _this._viewContainer.remove(adjustedPreviousIndex); - } - else { - var view = _this._viewContainer.get(adjustedPreviousIndex); - _this._viewContainer.move(view, currentIndex); - var tuple = new RecordViewTuple(item, view); - insertTuples.push(tuple); - } - }); - for (var i = 0; i < insertTuples.length; i++) { - this._perViewChange(insertTuples[i].view, insertTuples[i].record); - } - for (var i = 0, ilen = this._viewContainer.length; i < ilen; i++) { - var viewRef = this._viewContainer.get(i); - viewRef.context.index = i; - viewRef.context.count = ilen; - } - changes.forEachIdentityChange(function (record) { - var viewRef = _this._viewContainer.get(record.currentIndex); - viewRef.context.$implicit = record.item; - }); - }; - NgFor.prototype._perViewChange = function (view, record) { - view.context.$implicit = record.item; - }; - return NgFor; - }()); - /** @nocollapse */ - NgFor.decorators = [ - { type: _angular_core.Directive, args: [{ selector: '[ngFor][ngForOf]' },] }, - ]; - /** @nocollapse */ - NgFor.ctorParameters = [ - { type: _angular_core.ViewContainerRef, }, - { type: _angular_core.TemplateRef, }, - { type: _angular_core.IterableDiffers, }, - { type: _angular_core.ChangeDetectorRef, }, - ]; - /** @nocollapse */ - NgFor.propDecorators = { - 'ngForOf': [{ type: _angular_core.Input },], - 'ngForTrackBy': [{ type: _angular_core.Input },], - 'ngForTemplate': [{ type: _angular_core.Input },], - }; - var RecordViewTuple = (function () { - function RecordViewTuple(record, view) { - this.record = record; - this.view = view; - } - return RecordViewTuple; - }()); - var NgIf = (function () { - function NgIf(_viewContainer, _templateRef) { - this._viewContainer = _viewContainer; - this._templateRef = _templateRef; - this._prevCondition = null; - } - Object.defineProperty(NgIf.prototype, "ngIf", { - set: function (newCondition) { - if (newCondition && (isBlank(this._prevCondition) || !this._prevCondition)) { - this._prevCondition = true; - this._viewContainer.createEmbeddedView(this._templateRef); - } - else if (!newCondition && (isBlank(this._prevCondition) || this._prevCondition)) { - this._prevCondition = false; - this._viewContainer.clear(); - } - }, - enumerable: true, - configurable: true - }); - return NgIf; - }()); - /** @nocollapse */ - NgIf.decorators = [ - { type: _angular_core.Directive, args: [{ selector: '[ngIf]' },] }, - ]; - /** @nocollapse */ - NgIf.ctorParameters = [ - { type: _angular_core.ViewContainerRef, }, - { type: _angular_core.TemplateRef, }, - ]; - /** @nocollapse */ - NgIf.propDecorators = { - 'ngIf': [{ type: _angular_core.Input },], - }; - /** - * @license - * Copyright Google Inc. All Rights Reserved. - * - * Use of this source code is governed by an MIT-style license that can be - * found in the LICENSE file at https://angular.io/license - */ - /** - * @experimental - */ - var NgLocalization = (function () { - function NgLocalization() { - } - return NgLocalization; - }()); - /** - * Returns the plural category for a given value. - * - "=value" when the case exists, - * - the plural category otherwise - * - * @internal - */ - function getPluralCategory(value, cases, ngLocalization) { - var nbCase = "=" + value; - return cases.indexOf(nbCase) > -1 ? nbCase : ngLocalization.getPluralCategory(value); - } - var _CASE_DEFAULT = new Object(); - // TODO: remove when fully deprecated - var _warned = false; - var SwitchView = (function () { - function SwitchView(_viewContainerRef, _templateRef) { - this._viewContainerRef = _viewContainerRef; - this._templateRef = _templateRef; - } - SwitchView.prototype.create = function () { this._viewContainerRef.createEmbeddedView(this._templateRef); }; - SwitchView.prototype.destroy = function () { this._viewContainerRef.clear(); }; - return SwitchView; - }()); - var NgSwitch = (function () { - function NgSwitch() { - this._useDefault = false; - this._valueViews = new Map(); - this._activeViews = []; - } - Object.defineProperty(NgSwitch.prototype, "ngSwitch", { - set: function (value) { - // Empty the currently active ViewContainers - this._emptyAllActiveViews(); - // Add the ViewContainers matching the value (with a fallback to default) - this._useDefault = false; - var views = this._valueViews.get(value); - if (isBlank(views)) { - this._useDefault = true; - views = normalizeBlank(this._valueViews.get(_CASE_DEFAULT)); - } - this._activateViews(views); - this._switchValue = value; - }, - enumerable: true, - configurable: true - }); - /** @internal */ - NgSwitch.prototype._onCaseValueChanged = function (oldCase, newCase, view) { - this._deregisterView(oldCase, view); - this._registerView(newCase, view); - if (oldCase === this._switchValue) { - view.destroy(); - ListWrapper.remove(this._activeViews, view); - } - else if (newCase === this._switchValue) { - if (this._useDefault) { - this._useDefault = false; - this._emptyAllActiveViews(); - } - view.create(); - this._activeViews.push(view); - } - // Switch to default when there is no more active ViewContainers - if (this._activeViews.length === 0 && !this._useDefault) { - this._useDefault = true; - this._activateViews(this._valueViews.get(_CASE_DEFAULT)); - } - }; - /** @internal */ - NgSwitch.prototype._emptyAllActiveViews = function () { - var activeContainers = this._activeViews; - for (var i = 0; i < activeContainers.length; i++) { - activeContainers[i].destroy(); - } - this._activeViews = []; - }; - /** @internal */ - NgSwitch.prototype._activateViews = function (views) { - // TODO(vicb): assert(this._activeViews.length === 0); - if (isPresent(views)) { - for (var i = 0; i < views.length; i++) { - views[i].create(); - } - this._activeViews = views; - } - }; - /** @internal */ - NgSwitch.prototype._registerView = function (value, view) { - var views = this._valueViews.get(value); - if (isBlank(views)) { - views = []; - this._valueViews.set(value, views); - } - views.push(view); - }; - /** @internal */ - NgSwitch.prototype._deregisterView = function (value, view) { - // `_CASE_DEFAULT` is used a marker for non-registered cases - if (value === _CASE_DEFAULT) - return; - var views = this._valueViews.get(value); - if (views.length == 1) { - this._valueViews.delete(value); - } - else { - ListWrapper.remove(views, view); - } - }; - return NgSwitch; - }()); - /** @nocollapse */ - NgSwitch.decorators = [ - { type: _angular_core.Directive, args: [{ selector: '[ngSwitch]' },] }, - ]; - /** @nocollapse */ - NgSwitch.propDecorators = { - 'ngSwitch': [{ type: _angular_core.Input },], - }; - var NgSwitchCase = (function () { - function NgSwitchCase(viewContainer, templateRef, ngSwitch) { - // `_CASE_DEFAULT` is used as a marker for a not yet initialized value - /** @internal */ - this._value = _CASE_DEFAULT; - this._switch = ngSwitch; - this._view = new SwitchView(viewContainer, templateRef); - } - Object.defineProperty(NgSwitchCase.prototype, "ngSwitchCase", { - set: function (value) { - this._switch._onCaseValueChanged(this._value, value, this._view); - this._value = value; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(NgSwitchCase.prototype, "ngSwitchWhen", { - set: function (value) { - if (!_warned) { - _warned = true; - console.warn('*ngSwitchWhen is deprecated and will be removed. Use *ngSwitchCase instead'); - } - this._switch._onCaseValueChanged(this._value, value, this._view); - this._value = value; - }, - enumerable: true, - configurable: true - }); - return NgSwitchCase; - }()); - /** @nocollapse */ - NgSwitchCase.decorators = [ - { type: _angular_core.Directive, args: [{ selector: '[ngSwitchCase],[ngSwitchWhen]' },] }, - ]; - /** @nocollapse */ - NgSwitchCase.ctorParameters = [ - { type: _angular_core.ViewContainerRef, }, - { type: _angular_core.TemplateRef, }, - { type: NgSwitch, decorators: [{ type: _angular_core.Host },] }, - ]; - /** @nocollapse */ - NgSwitchCase.propDecorators = { - 'ngSwitchCase': [{ type: _angular_core.Input },], - 'ngSwitchWhen': [{ type: _angular_core.Input },], - }; - var NgSwitchDefault = (function () { - function NgSwitchDefault(viewContainer, templateRef, sswitch) { - sswitch._registerView(_CASE_DEFAULT, new SwitchView(viewContainer, templateRef)); - } - return NgSwitchDefault; - }()); - /** @nocollapse */ - NgSwitchDefault.decorators = [ - { type: _angular_core.Directive, args: [{ selector: '[ngSwitchDefault]' },] }, - ]; - /** @nocollapse */ - NgSwitchDefault.ctorParameters = [ - { type: _angular_core.ViewContainerRef, }, - { type: _angular_core.TemplateRef, }, - { type: NgSwitch, decorators: [{ type: _angular_core.Host },] }, - ]; - var NgPlural = (function () { - function NgPlural(_localization) { - this._localization = _localization; - this._caseViews = {}; - } - Object.defineProperty(NgPlural.prototype, "ngPlural", { - set: function (value) { - this._switchValue = value; - this._updateView(); - }, - enumerable: true, - configurable: true - }); - NgPlural.prototype.addCase = function (value, switchView) { this._caseViews[value] = switchView; }; - /** @internal */ - NgPlural.prototype._updateView = function () { - this._clearViews(); - var key = getPluralCategory(this._switchValue, Object.keys(this._caseViews), this._localization); - this._activateView(this._caseViews[key]); - }; - /** @internal */ - NgPlural.prototype._clearViews = function () { - if (isPresent(this._activeView)) - this._activeView.destroy(); - }; - /** @internal */ - NgPlural.prototype._activateView = function (view) { - if (!isPresent(view)) - return; - this._activeView = view; - this._activeView.create(); - }; - return NgPlural; - }()); - /** @nocollapse */ - NgPlural.decorators = [ - { type: _angular_core.Directive, args: [{ selector: '[ngPlural]' },] }, - ]; - /** @nocollapse */ - NgPlural.ctorParameters = [ - { type: NgLocalization, }, - ]; - /** @nocollapse */ - NgPlural.propDecorators = { - 'ngPlural': [{ type: _angular_core.Input },], - }; - var NgPluralCase = (function () { - function NgPluralCase(value, template, viewContainer, ngPlural) { - this.value = value; - ngPlural.addCase(value, new SwitchView(viewContainer, template)); - } - return NgPluralCase; - }()); - /** @nocollapse */ - NgPluralCase.decorators = [ - { type: _angular_core.Directive, args: [{ selector: '[ngPluralCase]' },] }, - ]; - /** @nocollapse */ - NgPluralCase.ctorParameters = [ - { type: undefined, decorators: [{ type: _angular_core.Attribute, args: ['ngPluralCase',] },] }, - { type: _angular_core.TemplateRef, }, - { type: _angular_core.ViewContainerRef, }, - { type: NgPlural, decorators: [{ type: _angular_core.Host },] }, - ]; - var NgStyle = (function () { - function NgStyle(_differs, _ngEl, _renderer) { - this._differs = _differs; - this._ngEl = _ngEl; - this._renderer = _renderer; - } - Object.defineProperty(NgStyle.prototype, "ngStyle", { - set: function (v) { - this._ngStyle = v; - if (isBlank(this._differ) && isPresent(v)) { - this._differ = this._differs.find(this._ngStyle).create(null); - } - }, - enumerable: true, - configurable: true - }); - NgStyle.prototype.ngDoCheck = function () { - if (isPresent(this._differ)) { - var changes = this._differ.diff(this._ngStyle); - if (isPresent(changes)) { - this._applyChanges(changes); - } - } - }; - NgStyle.prototype._applyChanges = function (changes) { - var _this = this; - changes.forEachRemovedItem(function (record) { _this._setStyle(record.key, null); }); - changes.forEachAddedItem(function (record) { _this._setStyle(record.key, record.currentValue); }); - changes.forEachChangedItem(function (record) { _this._setStyle(record.key, record.currentValue); }); - }; - NgStyle.prototype._setStyle = function (name, val) { - var nameParts = name.split('.'); - var nameToSet = nameParts[0]; - var valToSet = isPresent(val) && nameParts.length === 2 ? "" + val + nameParts[1] : val; - this._renderer.setElementStyle(this._ngEl.nativeElement, nameToSet, valToSet); - }; - return NgStyle; - }()); - /** @nocollapse */ - NgStyle.decorators = [ - { type: _angular_core.Directive, args: [{ selector: '[ngStyle]' },] }, - ]; - /** @nocollapse */ - NgStyle.ctorParameters = [ - { type: _angular_core.KeyValueDiffers, }, - { type: _angular_core.ElementRef, }, - { type: _angular_core.Renderer, }, - ]; - /** @nocollapse */ - NgStyle.propDecorators = { - 'ngStyle': [{ type: _angular_core.Input },], - }; - var NgTemplateOutlet = (function () { - function NgTemplateOutlet(_viewContainerRef) { - this._viewContainerRef = _viewContainerRef; - } - Object.defineProperty(NgTemplateOutlet.prototype, "ngOutletContext", { - set: function (context) { this._context = context; }, - enumerable: true, - configurable: true - }); - Object.defineProperty(NgTemplateOutlet.prototype, "ngTemplateOutlet", { - set: function (templateRef) { this._templateRef = templateRef; }, - enumerable: true, - configurable: true - }); - NgTemplateOutlet.prototype.ngOnChanges = function () { - if (this._viewRef) { - this._viewContainerRef.remove(this._viewContainerRef.indexOf(this._viewRef)); - } - if (this._templateRef) { - this._viewRef = this._viewContainerRef.createEmbeddedView(this._templateRef, this._context); - } - }; - return NgTemplateOutlet; - }()); - /** @nocollapse */ - NgTemplateOutlet.decorators = [ - { type: _angular_core.Directive, args: [{ selector: '[ngTemplateOutlet]' },] }, - ]; - /** @nocollapse */ - NgTemplateOutlet.ctorParameters = [ - { type: _angular_core.ViewContainerRef, }, - ]; - /** @nocollapse */ - NgTemplateOutlet.propDecorators = { - 'ngOutletContext': [{ type: _angular_core.Input },], - 'ngTemplateOutlet': [{ type: _angular_core.Input },], - }; - /** - * A collection of Angular core directives that are likely to be used in each and every Angular - * application. - * - * This collection can be used to quickly enumerate all the built-in directives in the `directives` - * property of the `@Component` annotation. - * - * ### Example ([live demo](http://plnkr.co/edit/yakGwpCdUkg0qfzX5m8g?p=preview)) - * - * Instead of writing: - * - * ```typescript - * import {NgClass, NgIf, NgFor, NgSwitch, NgSwitchWhen, NgSwitchDefault} from '@angular/common'; - * import {OtherDirective} from './myDirectives'; - * - * @Component({ - * selector: 'my-component', - * templateUrl: 'myComponent.html', - * directives: [NgClass, NgIf, NgFor, NgSwitch, NgSwitchWhen, NgSwitchDefault, OtherDirective] - * }) - * export class MyComponent { - * ... - * } - * ``` - * one could import all the core directives at once: - * - * ```typescript - * import {CORE_DIRECTIVES} from '@angular/common'; - * import {OtherDirective} from './myDirectives'; - * - * @Component({ - * selector: 'my-component', - * templateUrl: 'myComponent.html', - * directives: [CORE_DIRECTIVES, OtherDirective] - * }) - * export class MyComponent { - * ... - * } - * ``` - * - * @stable - */ - var CORE_DIRECTIVES = [ - NgClass, - NgFor, - NgIf, - NgTemplateOutlet, - NgStyle, - NgSwitch, - NgSwitchCase, - NgSwitchDefault, - NgPlural, - NgPluralCase, - ]; - /** - * A collection of Angular core directives that are likely to be used in each and every Angular - * application. This includes core directives (e.g., NgIf and NgFor), and forms directives (e.g., - * NgModel). - * - * This collection can be used to quickly enumerate all the built-in directives in the `directives` - * property of the `@Component` decorator. - * - * ### Example - * - * Instead of writing: - * - * ```typescript - * import {NgClass, NgIf, NgFor, NgSwitch, NgSwitchWhen, NgSwitchDefault, NgModel, NgForm} from - * '@angular/common'; - * import {OtherDirective} from './myDirectives'; - * - * @Component({ - * selector: 'my-component', - * templateUrl: 'myComponent.html', - * directives: [NgClass, NgIf, NgFor, NgSwitch, NgSwitchWhen, NgSwitchDefault, NgModel, NgForm, - * OtherDirective] - * }) - * export class MyComponent { - * ... - * } - * ``` - * one could import all the common directives at once: - * - * ```typescript - * import {COMMON_DIRECTIVES} from '@angular/common'; - * import {OtherDirective} from './myDirectives'; - * - * @Component({ - * selector: 'my-component', - * templateUrl: 'myComponent.html', - * directives: [COMMON_DIRECTIVES, OtherDirective] - * }) - * export class MyComponent { - * ... - * } - * ``` - * - * @experimental Contains forms which are experimental. - */ - var COMMON_DIRECTIVES = [CORE_DIRECTIVES]; - var InvalidPipeArgumentException = (function (_super) { - __extends(InvalidPipeArgumentException, _super); - function InvalidPipeArgumentException(type, value) { - _super.call(this, "Invalid argument '" + value + "' for pipe '" + stringify(type) + "'"); - } - return InvalidPipeArgumentException; - }(BaseException)); - var ObservableStrategy = (function () { - function ObservableStrategy() { - } - ObservableStrategy.prototype.createSubscription = function (async, updateLatestValue) { - return async.subscribe({ next: updateLatestValue, error: function (e) { throw e; } }); - }; - ObservableStrategy.prototype.dispose = function (subscription) { subscription.unsubscribe(); }; - ObservableStrategy.prototype.onDestroy = function (subscription) { subscription.unsubscribe(); }; - return ObservableStrategy; - }()); - var PromiseStrategy = (function () { - function PromiseStrategy() { - } - PromiseStrategy.prototype.createSubscription = function (async, updateLatestValue) { - return async.then(updateLatestValue, function (e) { throw e; }); - }; - PromiseStrategy.prototype.dispose = function (subscription) { }; - PromiseStrategy.prototype.onDestroy = function (subscription) { }; - return PromiseStrategy; - }()); - var _promiseStrategy = new PromiseStrategy(); - var _observableStrategy = new ObservableStrategy(); - var AsyncPipe = (function () { - function AsyncPipe(_ref) { - /** @internal */ - this._latestValue = null; - /** @internal */ - this._latestReturnedValue = null; - /** @internal */ - this._subscription = null; - /** @internal */ - this._obj = null; - this._strategy = null; - this._ref = _ref; - } - AsyncPipe.prototype.ngOnDestroy = function () { - if (isPresent(this._subscription)) { - this._dispose(); - } - }; - AsyncPipe.prototype.transform = function (obj) { - if (isBlank(this._obj)) { - if (isPresent(obj)) { - this._subscribe(obj); - } - this._latestReturnedValue = this._latestValue; - return this._latestValue; - } - if (obj !== this._obj) { - this._dispose(); - return this.transform(obj); - } - if (this._latestValue === this._latestReturnedValue) { - return this._latestReturnedValue; - } - else { - this._latestReturnedValue = this._latestValue; - return _angular_core.WrappedValue.wrap(this._latestValue); - } - }; - /** @internal */ - AsyncPipe.prototype._subscribe = function (obj) { - var _this = this; - this._obj = obj; - this._strategy = this._selectStrategy(obj); - this._subscription = this._strategy.createSubscription(obj, function (value) { return _this._updateLatestValue(obj, value); }); - }; - /** @internal */ - AsyncPipe.prototype._selectStrategy = function (obj) { - if (isPromise(obj)) { - return _promiseStrategy; - } - else if (obj.subscribe) { - return _observableStrategy; - } - else { - throw new InvalidPipeArgumentException(AsyncPipe, obj); - } - }; - /** @internal */ - AsyncPipe.prototype._dispose = function () { - this._strategy.dispose(this._subscription); - this._latestValue = null; - this._latestReturnedValue = null; - this._subscription = null; - this._obj = null; - }; - /** @internal */ - AsyncPipe.prototype._updateLatestValue = function (async, value) { - if (async === this._obj) { - this._latestValue = value; - this._ref.markForCheck(); - } - }; - return AsyncPipe; - }()); - /** @nocollapse */ - AsyncPipe.decorators = [ - { type: _angular_core.Pipe, args: [{ name: 'async', pure: false },] }, - ]; - /** @nocollapse */ - AsyncPipe.ctorParameters = [ - { type: _angular_core.ChangeDetectorRef, }, - ]; - /** - * @license - * Copyright Google Inc. All Rights Reserved. - * - * Use of this source code is governed by an MIT-style license that can be - * found in the LICENSE file at https://angular.io/license - */ - var NumberFormatStyle; - (function (NumberFormatStyle) { - NumberFormatStyle[NumberFormatStyle["Decimal"] = 0] = "Decimal"; - NumberFormatStyle[NumberFormatStyle["Percent"] = 1] = "Percent"; - NumberFormatStyle[NumberFormatStyle["Currency"] = 2] = "Currency"; - })(NumberFormatStyle || (NumberFormatStyle = {})); - var NumberFormatter = (function () { - function NumberFormatter() { - } - NumberFormatter.format = function (num, locale, style, _a) { - var _b = _a === void 0 ? {} : _a, minimumIntegerDigits = _b.minimumIntegerDigits, minimumFractionDigits = _b.minimumFractionDigits, maximumFractionDigits = _b.maximumFractionDigits, currency = _b.currency, _c = _b.currencyAsSymbol, currencyAsSymbol = _c === void 0 ? false : _c; - var options = { - minimumIntegerDigits: minimumIntegerDigits, - minimumFractionDigits: minimumFractionDigits, - maximumFractionDigits: maximumFractionDigits, - style: NumberFormatStyle[style].toLowerCase() - }; - if (style == NumberFormatStyle.Currency) { - options.currency = currency; - options.currencyDisplay = currencyAsSymbol ? 'symbol' : 'code'; - } - return new Intl.NumberFormat(locale, options).format(num); + return new Intl.NumberFormat(locale, options).format(num); }; return NumberFormatter; }()); @@ -1577,11 +883,14 @@ var __extends = (this && this.__extends) || function (d, b) { return result.split(' ')[0]; }; } + function intlDateFormat(date, locale, options) { + return new Intl.DateTimeFormat(locale, options).format(date).replace(/[\u200e\u200f]/g, ''); + } function timeZoneGetter(timezone) { // To workaround `Intl` API restriction for single timezone let format with 24 hours - var format = { hour: '2-digit', hour12: false, timeZoneName: timezone }; + var options = { hour: '2-digit', hour12: false, timeZoneName: timezone }; return function (date, locale) { - var result = new Intl.DateTimeFormat(locale, format).format(date); + var result = intlDateFormat(date, locale, options); // Then extract first 3 letters that related to hours return result ? result.substring(3) : ''; }; @@ -1606,9 +915,7 @@ var __extends = (this && this.__extends) || function (d, b) { return result; } function datePartGetterFactory(ret) { - return function (date, locale) { - return new Intl.DateTimeFormat(locale, ret).format(date); - }; + return function (date, locale) { return intlDateFormat(date, locale, ret); }; } var datePartsFormatterCache = new Map(); function dateFormatter(format, date, locale) { @@ -1656,20 +963,87 @@ var __extends = (this && this.__extends) || function (d, b) { }; return DateFormatter; }()); - // TODO: move to a global configurable location along with other i18n components. - var defaultLocale = 'en-US'; + + /** + * Formats a date value to a string based on the requested format. + * + * WARNINGS: + * - this pipe is marked as pure hence it will not be re-evaluated when the input is mutated. + * Instead users should treat the date as an immutable object and change the reference when the + * pipe needs to re-run (this is to avoid reformatting the date on every change detection run + * which would be an expensive operation). + * - this pipe uses the Internationalization API. Therefore it is only reliable in Chrome and Opera + * browsers. + * + * ## Usage + * + * expression | date[:format] + * + * where `expression` is a date object or a number (milliseconds since UTC epoch) or an ISO string + * (https://www.w3.org/TR/NOTE-datetime) and `format` indicates which date/time components to + * include: + * + * | Component | Symbol | Short Form | Long Form | Numeric | 2-digit | + * |-----------|:------:|--------------|-------------------|-----------|-----------| + * | era | G | G (AD) | GGGG (Anno Domini)| - | - | + * | year | y | - | - | y (2015) | yy (15) | + * | month | M | MMM (Sep) | MMMM (September) | M (9) | MM (09) | + * | day | d | - | - | d (3) | dd (03) | + * | weekday | E | EEE (Sun) | EEEE (Sunday) | - | - | + * | hour | j | - | - | j (13) | jj (13) | + * | hour12 | h | - | - | h (1 PM) | hh (01 PM)| + * | hour24 | H | - | - | H (13) | HH (13) | + * | minute | m | - | - | m (5) | mm (05) | + * | second | s | - | - | s (9) | ss (09) | + * | timezone | z | - | z (Pacific Standard Time)| - | - | + * | timezone | Z | Z (GMT-8:00) | - | - | - | + * | timezone | a | a (PM) | - | - | - | + * + * In javascript, only the components specified will be respected (not the ordering, + * punctuations, ...) and details of the formatting will be dependent on the locale. + * + * `format` can also be one of the following predefined formats: + * + * - `'medium'`: equivalent to `'yMMMdjms'` (e.g. Sep 3, 2010, 12:05:08 PM for en-US) + * - `'short'`: equivalent to `'yMdjm'` (e.g. 9/3/2010, 12:05 PM for en-US) + * - `'fullDate'`: equivalent to `'yMMMMEEEEd'` (e.g. Friday, September 3, 2010 for en-US) + * - `'longDate'`: equivalent to `'yMMMMd'` (e.g. September 3, 2010) + * - `'mediumDate'`: equivalent to `'yMMMd'` (e.g. Sep 3, 2010 for en-US) + * - `'shortDate'`: equivalent to `'yMd'` (e.g. 9/3/2010 for en-US) + * - `'mediumTime'`: equivalent to `'jms'` (e.g. 12:05:08 PM for en-US) + * - `'shortTime'`: equivalent to `'jm'` (e.g. 12:05 PM for en-US) + * + * Timezone of the formatted text will be the local system timezone of the end-users machine. + * + * ### Examples + * + * Assuming `dateObj` is (year: 2015, month: 6, day: 15, hour: 21, minute: 43, second: 11) + * in the _local_ time and locale is 'en-US': + * + * ``` + * {{ dateObj | date }} // output is 'Jun 15, 2015' + * {{ dateObj | date:'medium' }} // output is 'Jun 15, 2015, 9:43:11 PM' + * {{ dateObj | date:'shortTime' }} // output is '9:43 PM' + * {{ dateObj | date:'mmss' }} // output is '43:11' + * ``` + * + * {@example core/pipes/ts/date_pipe/date_pipe_example.ts region='DatePipe'} + * + * @stable + */ var DatePipe = (function () { - function DatePipe() { + function DatePipe(_locale) { + this._locale = _locale; } DatePipe.prototype.transform = function (value, pattern) { if (pattern === void 0) { pattern = 'mediumDate'; } if (isBlank(value)) return null; if (!this.supports(value)) { - throw new InvalidPipeArgumentException(DatePipe, value); + throw new InvalidPipeArgumentError(DatePipe, value); } if (NumberWrapper.isNumeric(value)) { - value = DateWrapper.fromMillis(NumberWrapper.parseInt(value, 10)); + value = DateWrapper.fromMillis(parseFloat(value)); } else if (isString(value)) { value = DateWrapper.fromISOString(value); @@ -1677,7 +1051,7 @@ var __extends = (this && this.__extends) || function (d, b) { if (StringMapWrapper.contains(DatePipe._ALIASES, pattern)) { pattern = StringMapWrapper.get(DatePipe._ALIASES, pattern); } - return DateFormatter.format(value, defaultLocale, pattern); + return DateFormatter.format(value, this._locale, pattern); }; DatePipe.prototype.supports = function (obj) { if (isDate(obj) || NumberWrapper.isNumeric(obj)) { @@ -1688,24 +1062,551 @@ var __extends = (this && this.__extends) || function (d, b) { } return false; }; + /** @internal */ + DatePipe._ALIASES = { + 'medium': 'yMMMdjms', + 'short': 'yMdjm', + 'fullDate': 'yMMMMEEEEd', + 'longDate': 'yMMMMd', + 'mediumDate': 'yMMMd', + 'shortDate': 'yMd', + 'mediumTime': 'jms', + 'shortTime': 'jm' + }; + DatePipe.decorators = [ + { type: _angular_core.Pipe, args: [{ name: 'date', pure: true },] }, + ]; + /** @nocollapse */ + DatePipe.ctorParameters = [ + { type: undefined, decorators: [{ type: _angular_core.Inject, args: [_angular_core.LOCALE_ID,] },] }, + ]; return DatePipe; }()); - /** @internal */ - DatePipe._ALIASES = { - 'medium': 'yMMMdjms', - 'short': 'yMdjm', - 'fullDate': 'yMMMMEEEEd', - 'longDate': 'yMMMMd', - 'mediumDate': 'yMMMd', - 'shortDate': 'yMd', - 'mediumTime': 'jms', - 'shortTime': 'jm' + + /** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + var __extends$2 = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; - /** @nocollapse */ - DatePipe.decorators = [ - { type: _angular_core.Pipe, args: [{ name: 'date', pure: true },] }, - ]; + /** + * @experimental + */ + var NgLocalization = (function () { + function NgLocalization() { + } + return NgLocalization; + }()); + /** + * Returns the plural category for a given value. + * - "=value" when the case exists, + * - the plural category otherwise + * + * @internal + */ + function getPluralCategory(value, cases, ngLocalization) { + var nbCase = "=" + value; + return cases.indexOf(nbCase) > -1 ? nbCase : ngLocalization.getPluralCategory(value); + } + /** + * Returns the plural case based on the locale + * + * @experimental + */ + var NgLocaleLocalization = (function (_super) { + __extends$2(NgLocaleLocalization, _super); + function NgLocaleLocalization(_locale) { + _super.call(this); + this._locale = _locale; + } + NgLocaleLocalization.prototype.getPluralCategory = function (value) { + var plural = getPluralCase(this._locale, value); + switch (plural) { + case Plural.Zero: + return 'zero'; + case Plural.One: + return 'one'; + case Plural.Two: + return 'two'; + case Plural.Few: + return 'few'; + case Plural.Many: + return 'many'; + default: + return 'other'; + } + }; + NgLocaleLocalization.decorators = [ + { type: _angular_core.Injectable }, + ]; + /** @nocollapse */ + NgLocaleLocalization.ctorParameters = [ + { type: undefined, decorators: [{ type: _angular_core.Inject, args: [_angular_core.LOCALE_ID,] },] }, + ]; + return NgLocaleLocalization; + }(NgLocalization)); + // This is generated code DO NOT MODIFY + // see angular2/script/cldr/gen_plural_rules.js + /** @experimental */ + var Plural; + (function (Plural) { + Plural[Plural["Zero"] = 0] = "Zero"; + Plural[Plural["One"] = 1] = "One"; + Plural[Plural["Two"] = 2] = "Two"; + Plural[Plural["Few"] = 3] = "Few"; + Plural[Plural["Many"] = 4] = "Many"; + Plural[Plural["Other"] = 5] = "Other"; + })(Plural || (Plural = {})); + /** + * Returns the plural case based on the locale + * + * @experimental + */ + function getPluralCase(locale, nLike) { + // TODO(vicb): lazy compute + if (typeof nLike === 'string') { + nLike = parseInt(nLike, 10); + } + var n = nLike; + var nDecimal = n.toString().replace(/^[^.]*\.?/, ''); + var i = Math.floor(Math.abs(n)); + var v = nDecimal.length; + var f = parseInt(nDecimal, 10); + var t = parseInt(n.toString().replace(/^[^.]*\.?|0+$/g, ''), 10) || 0; + var lang = locale.split('_')[0].toLowerCase(); + switch (lang) { + case 'af': + case 'asa': + case 'az': + case 'bem': + case 'bez': + case 'bg': + case 'brx': + case 'ce': + case 'cgg': + case 'chr': + case 'ckb': + case 'ee': + case 'el': + case 'eo': + case 'es': + case 'eu': + case 'fo': + case 'fur': + case 'gsw': + case 'ha': + case 'haw': + case 'hu': + case 'jgo': + case 'jmc': + case 'ka': + case 'kk': + case 'kkj': + case 'kl': + case 'ks': + case 'ksb': + case 'ky': + case 'lb': + case 'lg': + case 'mas': + case 'mgo': + case 'ml': + case 'mn': + case 'nb': + case 'nd': + case 'ne': + case 'nn': + case 'nnh': + case 'nyn': + case 'om': + case 'or': + case 'os': + case 'ps': + case 'rm': + case 'rof': + case 'rwk': + case 'saq': + case 'seh': + case 'sn': + case 'so': + case 'sq': + case 'ta': + case 'te': + case 'teo': + case 'tk': + case 'tr': + case 'ug': + case 'uz': + case 'vo': + case 'vun': + case 'wae': + case 'xog': + if (n === 1) + return Plural.One; + return Plural.Other; + case 'agq': + case 'bas': + case 'cu': + case 'dav': + case 'dje': + case 'dua': + case 'dyo': + case 'ebu': + case 'ewo': + case 'guz': + case 'kam': + case 'khq': + case 'ki': + case 'kln': + case 'kok': + case 'ksf': + case 'lrc': + case 'lu': + case 'luo': + case 'luy': + case 'mer': + case 'mfe': + case 'mgh': + case 'mua': + case 'mzn': + case 'nmg': + case 'nus': + case 'qu': + case 'rn': + case 'rw': + case 'sbp': + case 'twq': + case 'vai': + case 'yav': + case 'yue': + case 'zgh': + case 'ak': + case 'ln': + case 'mg': + case 'pa': + case 'ti': + if (n === Math.floor(n) && n >= 0 && n <= 1) + return Plural.One; + return Plural.Other; + case 'am': + case 'as': + case 'bn': + case 'fa': + case 'gu': + case 'hi': + case 'kn': + case 'mr': + case 'zu': + if (i === 0 || n === 1) + return Plural.One; + return Plural.Other; + case 'ar': + if (n === 0) + return Plural.Zero; + if (n === 1) + return Plural.One; + if (n === 2) + return Plural.Two; + if (n % 100 === Math.floor(n % 100) && n % 100 >= 3 && n % 100 <= 10) + return Plural.Few; + if (n % 100 === Math.floor(n % 100) && n % 100 >= 11 && n % 100 <= 99) + return Plural.Many; + return Plural.Other; + case 'ast': + case 'ca': + case 'de': + case 'en': + case 'et': + case 'fi': + case 'fy': + case 'gl': + case 'it': + case 'nl': + case 'sv': + case 'sw': + case 'ur': + case 'yi': + if (i === 1 && v === 0) + return Plural.One; + return Plural.Other; + case 'be': + if (n % 10 === 1 && !(n % 100 === 11)) + return Plural.One; + if (n % 10 === Math.floor(n % 10) && n % 10 >= 2 && n % 10 <= 4 && + !(n % 100 >= 12 && n % 100 <= 14)) + return Plural.Few; + if (n % 10 === 0 || n % 10 === Math.floor(n % 10) && n % 10 >= 5 && n % 10 <= 9 || + n % 100 === Math.floor(n % 100) && n % 100 >= 11 && n % 100 <= 14) + return Plural.Many; + return Plural.Other; + case 'br': + if (n % 10 === 1 && !(n % 100 === 11 || n % 100 === 71 || n % 100 === 91)) + return Plural.One; + if (n % 10 === 2 && !(n % 100 === 12 || n % 100 === 72 || n % 100 === 92)) + return Plural.Two; + if (n % 10 === Math.floor(n % 10) && (n % 10 >= 3 && n % 10 <= 4 || n % 10 === 9) && + !(n % 100 >= 10 && n % 100 <= 19 || n % 100 >= 70 && n % 100 <= 79 || + n % 100 >= 90 && n % 100 <= 99)) + return Plural.Few; + if (!(n === 0) && n % 1e6 === 0) + return Plural.Many; + return Plural.Other; + case 'bs': + case 'hr': + case 'sr': + if (v === 0 && i % 10 === 1 && !(i % 100 === 11) || f % 10 === 1 && !(f % 100 === 11)) + return Plural.One; + if (v === 0 && i % 10 === Math.floor(i % 10) && i % 10 >= 2 && i % 10 <= 4 && + !(i % 100 >= 12 && i % 100 <= 14) || + f % 10 === Math.floor(f % 10) && f % 10 >= 2 && f % 10 <= 4 && + !(f % 100 >= 12 && f % 100 <= 14)) + return Plural.Few; + return Plural.Other; + case 'cs': + case 'sk': + if (i === 1 && v === 0) + return Plural.One; + if (i === Math.floor(i) && i >= 2 && i <= 4 && v === 0) + return Plural.Few; + if (!(v === 0)) + return Plural.Many; + return Plural.Other; + case 'cy': + if (n === 0) + return Plural.Zero; + if (n === 1) + return Plural.One; + if (n === 2) + return Plural.Two; + if (n === 3) + return Plural.Few; + if (n === 6) + return Plural.Many; + return Plural.Other; + case 'da': + if (n === 1 || !(t === 0) && (i === 0 || i === 1)) + return Plural.One; + return Plural.Other; + case 'dsb': + case 'hsb': + if (v === 0 && i % 100 === 1 || f % 100 === 1) + return Plural.One; + if (v === 0 && i % 100 === 2 || f % 100 === 2) + return Plural.Two; + if (v === 0 && i % 100 === Math.floor(i % 100) && i % 100 >= 3 && i % 100 <= 4 || + f % 100 === Math.floor(f % 100) && f % 100 >= 3 && f % 100 <= 4) + return Plural.Few; + return Plural.Other; + case 'ff': + case 'fr': + case 'hy': + case 'kab': + if (i === 0 || i === 1) + return Plural.One; + return Plural.Other; + case 'fil': + if (v === 0 && (i === 1 || i === 2 || i === 3) || + v === 0 && !(i % 10 === 4 || i % 10 === 6 || i % 10 === 9) || + !(v === 0) && !(f % 10 === 4 || f % 10 === 6 || f % 10 === 9)) + return Plural.One; + return Plural.Other; + case 'ga': + if (n === 1) + return Plural.One; + if (n === 2) + return Plural.Two; + if (n === Math.floor(n) && n >= 3 && n <= 6) + return Plural.Few; + if (n === Math.floor(n) && n >= 7 && n <= 10) + return Plural.Many; + return Plural.Other; + case 'gd': + if (n === 1 || n === 11) + return Plural.One; + if (n === 2 || n === 12) + return Plural.Two; + if (n === Math.floor(n) && (n >= 3 && n <= 10 || n >= 13 && n <= 19)) + return Plural.Few; + return Plural.Other; + case 'gv': + if (v === 0 && i % 10 === 1) + return Plural.One; + if (v === 0 && i % 10 === 2) + return Plural.Two; + if (v === 0 && + (i % 100 === 0 || i % 100 === 20 || i % 100 === 40 || i % 100 === 60 || i % 100 === 80)) + return Plural.Few; + if (!(v === 0)) + return Plural.Many; + return Plural.Other; + case 'he': + if (i === 1 && v === 0) + return Plural.One; + if (i === 2 && v === 0) + return Plural.Two; + if (v === 0 && !(n >= 0 && n <= 10) && n % 10 === 0) + return Plural.Many; + return Plural.Other; + case 'is': + if (t === 0 && i % 10 === 1 && !(i % 100 === 11) || !(t === 0)) + return Plural.One; + return Plural.Other; + case 'ksh': + if (n === 0) + return Plural.Zero; + if (n === 1) + return Plural.One; + return Plural.Other; + case 'kw': + case 'naq': + case 'se': + case 'smn': + if (n === 1) + return Plural.One; + if (n === 2) + return Plural.Two; + return Plural.Other; + case 'lag': + if (n === 0) + return Plural.Zero; + if ((i === 0 || i === 1) && !(n === 0)) + return Plural.One; + return Plural.Other; + case 'lt': + if (n % 10 === 1 && !(n % 100 >= 11 && n % 100 <= 19)) + return Plural.One; + if (n % 10 === Math.floor(n % 10) && n % 10 >= 2 && n % 10 <= 9 && + !(n % 100 >= 11 && n % 100 <= 19)) + return Plural.Few; + if (!(f === 0)) + return Plural.Many; + return Plural.Other; + case 'lv': + case 'prg': + if (n % 10 === 0 || n % 100 === Math.floor(n % 100) && n % 100 >= 11 && n % 100 <= 19 || + v === 2 && f % 100 === Math.floor(f % 100) && f % 100 >= 11 && f % 100 <= 19) + return Plural.Zero; + if (n % 10 === 1 && !(n % 100 === 11) || v === 2 && f % 10 === 1 && !(f % 100 === 11) || + !(v === 2) && f % 10 === 1) + return Plural.One; + return Plural.Other; + case 'mk': + if (v === 0 && i % 10 === 1 || f % 10 === 1) + return Plural.One; + return Plural.Other; + case 'mt': + if (n === 1) + return Plural.One; + if (n === 0 || n % 100 === Math.floor(n % 100) && n % 100 >= 2 && n % 100 <= 10) + return Plural.Few; + if (n % 100 === Math.floor(n % 100) && n % 100 >= 11 && n % 100 <= 19) + return Plural.Many; + return Plural.Other; + case 'pl': + if (i === 1 && v === 0) + return Plural.One; + if (v === 0 && i % 10 === Math.floor(i % 10) && i % 10 >= 2 && i % 10 <= 4 && + !(i % 100 >= 12 && i % 100 <= 14)) + return Plural.Few; + if (v === 0 && !(i === 1) && i % 10 === Math.floor(i % 10) && i % 10 >= 0 && i % 10 <= 1 || + v === 0 && i % 10 === Math.floor(i % 10) && i % 10 >= 5 && i % 10 <= 9 || + v === 0 && i % 100 === Math.floor(i % 100) && i % 100 >= 12 && i % 100 <= 14) + return Plural.Many; + return Plural.Other; + case 'pt': + if (n === Math.floor(n) && n >= 0 && n <= 2 && !(n === 2)) + return Plural.One; + return Plural.Other; + case 'ro': + if (i === 1 && v === 0) + return Plural.One; + if (!(v === 0) || n === 0 || + !(n === 1) && n % 100 === Math.floor(n % 100) && n % 100 >= 1 && n % 100 <= 19) + return Plural.Few; + return Plural.Other; + case 'ru': + case 'uk': + if (v === 0 && i % 10 === 1 && !(i % 100 === 11)) + return Plural.One; + if (v === 0 && i % 10 === Math.floor(i % 10) && i % 10 >= 2 && i % 10 <= 4 && + !(i % 100 >= 12 && i % 100 <= 14)) + return Plural.Few; + if (v === 0 && i % 10 === 0 || + v === 0 && i % 10 === Math.floor(i % 10) && i % 10 >= 5 && i % 10 <= 9 || + v === 0 && i % 100 === Math.floor(i % 100) && i % 100 >= 11 && i % 100 <= 14) + return Plural.Many; + return Plural.Other; + case 'shi': + if (i === 0 || n === 1) + return Plural.One; + if (n === Math.floor(n) && n >= 2 && n <= 10) + return Plural.Few; + return Plural.Other; + case 'si': + if (n === 0 || n === 1 || i === 0 && f === 1) + return Plural.One; + return Plural.Other; + case 'sl': + if (v === 0 && i % 100 === 1) + return Plural.One; + if (v === 0 && i % 100 === 2) + return Plural.Two; + if (v === 0 && i % 100 === Math.floor(i % 100) && i % 100 >= 3 && i % 100 <= 4 || !(v === 0)) + return Plural.Few; + return Plural.Other; + case 'tzm': + if (n === Math.floor(n) && n >= 0 && n <= 1 || n === Math.floor(n) && n >= 11 && n <= 99) + return Plural.One; + return Plural.Other; + default: + return Plural.Other; + } + } + var _INTERPOLATION_REGEXP = /#/g; + /** + * Maps a value to a string that pluralizes the value properly. + * + * ## Usage + * + * expression | i18nPlural:mapping + * + * where `expression` is a number and `mapping` is an object that mimics the ICU format, + * see http://userguide.icu-project.org/formatparse/messages + * + * ## Example + * + * ``` + * @Component({ + * selector: 'app', + * template: ` + *
+ * {{ messages.length | i18nPlural: messageMapping }} + *
+ * `, + * // best practice is to define the locale at the application level + * providers: [{provide: LOCALE_ID, useValue: 'en_US'}] + * }) + * + * class MyApp { + * messages: any[]; + * messageMapping: {[k:string]: string} = { + * '=0': 'No messages.', + * '=1': 'One message.', + * 'other': '# messages.' + * } + * ... + * } + * ``` + * + * @experimental + */ var I18nPluralPipe = (function () { function I18nPluralPipe(_localization) { this._localization = _localization; @@ -1714,21 +1615,52 @@ var __extends = (this && this.__extends) || function (d, b) { if (isBlank(value)) return ''; if (!isStringMap(pluralMap)) { - throw new InvalidPipeArgumentException(I18nPluralPipe, pluralMap); + throw new InvalidPipeArgumentError(I18nPluralPipe, pluralMap); } var key = getPluralCategory(value, Object.keys(pluralMap), this._localization); return StringWrapper.replaceAll(pluralMap[key], _INTERPOLATION_REGEXP, value.toString()); }; + I18nPluralPipe.decorators = [ + { type: _angular_core.Pipe, args: [{ name: 'i18nPlural', pure: true },] }, + ]; + /** @nocollapse */ + I18nPluralPipe.ctorParameters = [ + { type: NgLocalization, }, + ]; return I18nPluralPipe; }()); - /** @nocollapse */ - I18nPluralPipe.decorators = [ - { type: _angular_core.Pipe, args: [{ name: 'i18nPlural', pure: true },] }, - ]; - /** @nocollapse */ - I18nPluralPipe.ctorParameters = [ - { type: NgLocalization, }, - ]; + + /** + * + * Generic selector that displays the string that matches the current value. + * + * ## Usage + * + * expression | i18nSelect:mapping + * + * where `mapping` is an object that indicates the text that should be displayed + * for different values of the provided `expression`. + * + * ## Example + * + * ``` + *
+ * {{ gender | i18nSelect: inviteMap }} + *
+ * + * class MyApp { + * gender: string = 'male'; + * inviteMap: any = { + * 'male': 'Invite him.', + * 'female': 'Invite her.', + * 'other': 'Invite them.' + * } + * ... + * } + * ``` + * + * @experimental + */ var I18nSelectPipe = (function () { function I18nSelectPipe() { } @@ -1736,26 +1668,47 @@ var __extends = (this && this.__extends) || function (d, b) { if (isBlank(value)) return ''; if (!isStringMap(mapping)) { - throw new InvalidPipeArgumentException(I18nSelectPipe, mapping); + throw new InvalidPipeArgumentError(I18nSelectPipe, mapping); } return mapping.hasOwnProperty(value) ? mapping[value] : ''; }; + I18nSelectPipe.decorators = [ + { type: _angular_core.Pipe, args: [{ name: 'i18nSelect', pure: true },] }, + ]; + /** @nocollapse */ + I18nSelectPipe.ctorParameters = []; return I18nSelectPipe; }()); - /** @nocollapse */ - I18nSelectPipe.decorators = [ - { type: _angular_core.Pipe, args: [{ name: 'i18nSelect', pure: true },] }, - ]; + + /** + * Transforms any input value using `JSON.stringify`. Useful for debugging. + * + * ### Example + * {@example core/pipes/ts/json_pipe/json_pipe_example.ts region='JsonPipe'} + * + * @stable + */ var JsonPipe = (function () { function JsonPipe() { } JsonPipe.prototype.transform = function (value) { return Json.stringify(value); }; + JsonPipe.decorators = [ + { type: _angular_core.Pipe, args: [{ name: 'json', pure: false },] }, + ]; + /** @nocollapse */ + JsonPipe.ctorParameters = []; return JsonPipe; }()); - /** @nocollapse */ - JsonPipe.decorators = [ - { type: _angular_core.Pipe, args: [{ name: 'json', pure: false },] }, - ]; + + /** + * Transforms text to lowercase. + * + * ### Example + * + * {@example core/pipes/ts/lowerupper_pipe/lowerupper_pipe_example.ts region='LowerUpperPipe'} + * + * @stable + */ var LowerCasePipe = (function () { function LowerCasePipe() { } @@ -1763,19 +1716,20 @@ var __extends = (this && this.__extends) || function (d, b) { if (isBlank(value)) return value; if (!isString(value)) { - throw new InvalidPipeArgumentException(LowerCasePipe, value); + throw new InvalidPipeArgumentError(LowerCasePipe, value); } return value.toLowerCase(); }; + LowerCasePipe.decorators = [ + { type: _angular_core.Pipe, args: [{ name: 'lowercase' },] }, + ]; + /** @nocollapse */ + LowerCasePipe.ctorParameters = []; return LowerCasePipe; }()); - /** @nocollapse */ - LowerCasePipe.decorators = [ - { type: _angular_core.Pipe, args: [{ name: 'lowercase' },] }, - ]; - var defaultLocale$1 = 'en-US'; + var _NUMBER_FORMAT_REGEXP = /^(\d+)?\.((\d+)(\-(\d+))?)?$/; - function formatNumber(pipe, value, style, digits, currency, currencyAsSymbol) { + function formatNumber(pipe, locale, value, style, digits, currency, currencyAsSymbol) { if (currency === void 0) { currency = null; } if (currencyAsSymbol === void 0) { currencyAsSymbol = false; } if (isBlank(value)) @@ -1783,7 +1737,7 @@ var __extends = (this && this.__extends) || function (d, b) { // Convert strings to numbers value = isString(value) && NumberWrapper.isNumeric(value) ? +value : value; if (!isNumber(value)) { - throw new InvalidPipeArgumentException(pipe, value); + throw new InvalidPipeArgumentError(pipe, value); } var minInt; var minFraction; @@ -1809,7 +1763,7 @@ var __extends = (this && this.__extends) || function (d, b) { maxFraction = NumberWrapper.parseIntAutoRadix(parts[5]); } } - return NumberFormatter.format(value, defaultLocale$1, style, { + return NumberFormatter.format(value, locale, style, { minimumIntegerDigits: minInt, minimumFractionDigits: minFraction, maximumFractionDigits: maxFraction, @@ -1817,2434 +1771,1165 @@ var __extends = (this && this.__extends) || function (d, b) { currencyAsSymbol: currencyAsSymbol }); } - var DecimalPipe = (function () { - function DecimalPipe() { - } - DecimalPipe.prototype.transform = function (value, digits) { - if (digits === void 0) { digits = null; } - return formatNumber(DecimalPipe, value, NumberFormatStyle.Decimal, digits); - }; - return DecimalPipe; - }()); - /** @nocollapse */ - DecimalPipe.decorators = [ - { type: _angular_core.Pipe, args: [{ name: 'number' },] }, - ]; - var PercentPipe = (function () { - function PercentPipe() { - } - PercentPipe.prototype.transform = function (value, digits) { - if (digits === void 0) { digits = null; } - return formatNumber(PercentPipe, value, NumberFormatStyle.Percent, digits); - }; - return PercentPipe; - }()); - /** @nocollapse */ - PercentPipe.decorators = [ - { type: _angular_core.Pipe, args: [{ name: 'percent' },] }, - ]; - var CurrencyPipe = (function () { - function CurrencyPipe() { - } - CurrencyPipe.prototype.transform = function (value, currencyCode, symbolDisplay, digits) { - if (currencyCode === void 0) { currencyCode = 'USD'; } - if (symbolDisplay === void 0) { symbolDisplay = false; } - if (digits === void 0) { digits = null; } - return formatNumber(CurrencyPipe, value, NumberFormatStyle.Currency, digits, currencyCode, symbolDisplay); - }; - return CurrencyPipe; - }()); - /** @nocollapse */ - CurrencyPipe.decorators = [ - { type: _angular_core.Pipe, args: [{ name: 'currency' },] }, - ]; - var ReplacePipe = (function () { - function ReplacePipe() { - } - ReplacePipe.prototype.transform = function (value, pattern, replacement) { - if (isBlank(value)) { - return value; - } - if (!this._supportedInput(value)) { - throw new InvalidPipeArgumentException(ReplacePipe, value); - } - var input = value.toString(); - if (!this._supportedPattern(pattern)) { - throw new InvalidPipeArgumentException(ReplacePipe, pattern); - } - if (!this._supportedReplacement(replacement)) { - throw new InvalidPipeArgumentException(ReplacePipe, replacement); - } - if (isFunction(replacement)) { - var rgxPattern = isString(pattern) ? new RegExp(pattern, 'g') : pattern; - return StringWrapper.replaceAllMapped(input, rgxPattern, replacement); - } - if (pattern instanceof RegExp) { - // use the replaceAll variant - return StringWrapper.replaceAll(input, pattern, replacement); - } - return StringWrapper.replace(input, pattern, replacement); - }; - ReplacePipe.prototype._supportedInput = function (input) { return isString(input) || isNumber(input); }; - ReplacePipe.prototype._supportedPattern = function (pattern) { - return isString(pattern) || pattern instanceof RegExp; - }; - ReplacePipe.prototype._supportedReplacement = function (replacement) { - return isString(replacement) || isFunction(replacement); - }; - return ReplacePipe; - }()); - /** @nocollapse */ - ReplacePipe.decorators = [ - { type: _angular_core.Pipe, args: [{ name: 'replace' },] }, - ]; - var SlicePipe = (function () { - function SlicePipe() { - } - SlicePipe.prototype.transform = function (value, start, end) { - if (end === void 0) { end = null; } - if (isBlank(value)) - return value; - if (!this.supports(value)) { - throw new InvalidPipeArgumentException(SlicePipe, value); - } - if (isString(value)) { - return StringWrapper.slice(value, start, end); - } - return ListWrapper.slice(value, start, end); - }; - SlicePipe.prototype.supports = function (obj) { return isString(obj) || isArray(obj); }; - return SlicePipe; - }()); - /** @nocollapse */ - SlicePipe.decorators = [ - { type: _angular_core.Pipe, args: [{ name: 'slice', pure: false },] }, - ]; - var UpperCasePipe = (function () { - function UpperCasePipe() { - } - UpperCasePipe.prototype.transform = function (value) { - if (isBlank(value)) - return value; - if (!isString(value)) { - throw new InvalidPipeArgumentException(UpperCasePipe, value); - } - return value.toUpperCase(); - }; - return UpperCasePipe; - }()); - /** @nocollapse */ - UpperCasePipe.decorators = [ - { type: _angular_core.Pipe, args: [{ name: 'uppercase' },] }, - ]; - /** - * A collection of Angular core pipes that are likely to be used in each and every - * application. - * - * This collection can be used to quickly enumerate all the built-in pipes in the `pipes` - * property of the `@Component` decorator. - * - * @experimental Contains i18n pipes which are experimental - */ - var COMMON_PIPES = [ - AsyncPipe, - UpperCasePipe, - LowerCasePipe, - JsonPipe, - SlicePipe, - DecimalPipe, - PercentPipe, - CurrencyPipe, - DatePipe, - ReplacePipe, - I18nPluralPipe, - I18nSelectPipe, - ]; - /** - * Used to provide a {@link ControlValueAccessor} for form controls. - * - * See {@link DefaultValueAccessor} for how to implement one. - * @experimental - */ - var NG_VALUE_ACCESSOR = new _angular_core.OpaqueToken('NgValueAccessor'); - var CHECKBOX_VALUE_ACCESSOR = { - provide: NG_VALUE_ACCESSOR, - useExisting: _angular_core.forwardRef(function () { return CheckboxControlValueAccessor; }), - multi: true - }; - var CheckboxControlValueAccessor = (function () { - function CheckboxControlValueAccessor(_renderer, _elementRef) { - this._renderer = _renderer; - this._elementRef = _elementRef; - this.onChange = function (_) { }; - this.onTouched = function () { }; - } - CheckboxControlValueAccessor.prototype.writeValue = function (value) { - this._renderer.setElementProperty(this._elementRef.nativeElement, 'checked', value); - }; - CheckboxControlValueAccessor.prototype.registerOnChange = function (fn) { this.onChange = fn; }; - CheckboxControlValueAccessor.prototype.registerOnTouched = function (fn) { this.onTouched = fn; }; - return CheckboxControlValueAccessor; - }()); - /** @nocollapse */ - CheckboxControlValueAccessor.decorators = [ - { type: _angular_core.Directive, args: [{ - selector: 'input[type=checkbox][ngControl],input[type=checkbox][ngFormControl],input[type=checkbox][ngModel]', - host: { '(change)': 'onChange($event.target.checked)', '(blur)': 'onTouched()' }, - providers: [CHECKBOX_VALUE_ACCESSOR] - },] }, - ]; - /** @nocollapse */ - CheckboxControlValueAccessor.ctorParameters = [ - { type: _angular_core.Renderer, }, - { type: _angular_core.ElementRef, }, - ]; - var DEFAULT_VALUE_ACCESSOR = { - provide: NG_VALUE_ACCESSOR, - useExisting: _angular_core.forwardRef(function () { return DefaultValueAccessor; }), - multi: true - }; - var DefaultValueAccessor = (function () { - function DefaultValueAccessor(_renderer, _elementRef) { - this._renderer = _renderer; - this._elementRef = _elementRef; - this.onChange = function (_) { }; - this.onTouched = function () { }; - } - DefaultValueAccessor.prototype.writeValue = function (value) { - var normalizedValue = isBlank(value) ? '' : value; - this._renderer.setElementProperty(this._elementRef.nativeElement, 'value', normalizedValue); - }; - DefaultValueAccessor.prototype.registerOnChange = function (fn) { this.onChange = fn; }; - DefaultValueAccessor.prototype.registerOnTouched = function (fn) { this.onTouched = fn; }; - return DefaultValueAccessor; - }()); - /** @nocollapse */ - DefaultValueAccessor.decorators = [ - { type: _angular_core.Directive, args: [{ - selector: 'input:not([type=checkbox])[ngControl],textarea[ngControl],input:not([type=checkbox])[ngFormControl],textarea[ngFormControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]', - // TODO: vsavkin replace the above selector with the one below it once - // https://github.com/angular/angular/issues/3011 is implemented - // selector: '[ngControl],[ngModel],[ngFormControl]', - host: { '(input)': 'onChange($event.target.value)', '(blur)': 'onTouched()' }, - providers: [DEFAULT_VALUE_ACCESSOR] - },] }, - ]; - /** @nocollapse */ - DefaultValueAccessor.ctorParameters = [ - { type: _angular_core.Renderer, }, - { type: _angular_core.ElementRef, }, - ]; - /** - * Providers for validators to be used for {@link Control}s in a form. - * - * Provide this using `multi: true` to add validators. - * - * ### Example - * - * {@example core/forms/ts/ng_validators/ng_validators.ts region='ng_validators'} - * @experimental - */ - var NG_VALIDATORS = new _angular_core.OpaqueToken('NgValidators'); - /** - * Providers for asynchronous validators to be used for {@link Control}s - * in a form. - * - * Provide this using `multi: true` to add validators. - * - * See {@link NG_VALIDATORS} for more details. - * - * @experimental - */ - var NG_ASYNC_VALIDATORS = new _angular_core.OpaqueToken('NgAsyncValidators'); - /** - * Provides a set of validators used by form controls. - * - * A validator is a function that processes a {@link Control} or collection of - * controls and returns a map of errors. A null map means that validation has passed. - * - * ### Example - * - * ```typescript - * var loginControl = new Control("", Validators.required) - * ``` - * - * @experimental - */ - var Validators = (function () { - function Validators() { - } - /** - * Validator that requires controls to have a non-empty value. - */ - Validators.required = function (control) { - return isBlank(control.value) || (isString(control.value) && control.value == '') ? - { 'required': true } : - null; - }; - /** - * Validator that requires controls to have a value of a minimum length. - */ - Validators.minLength = function (minLength) { - return function (control) { - if (isPresent(Validators.required(control))) - return null; - var v = control.value; - return v.length < minLength ? - { 'minlength': { 'requiredLength': minLength, 'actualLength': v.length } } : - null; - }; - }; - /** - * Validator that requires controls to have a value of a maximum length. - */ - Validators.maxLength = function (maxLength) { - return function (control) { - if (isPresent(Validators.required(control))) - return null; - var v = control.value; - return v.length > maxLength ? - { 'maxlength': { 'requiredLength': maxLength, 'actualLength': v.length } } : - null; - }; - }; - /** - * Validator that requires a control to match a regex to its value. - */ - Validators.pattern = function (pattern) { - return function (control) { - if (isPresent(Validators.required(control))) - return null; - var regex = new RegExp("^" + pattern + "$"); - var v = control.value; - return regex.test(v) ? null : - { 'pattern': { 'requiredPattern': "^" + pattern + "$", 'actualValue': v } }; - }; - }; - /** - * No-op validator. - */ - Validators.nullValidator = function (c) { return null; }; - /** - * Compose multiple validators into a single function that returns the union - * of the individual error maps. - */ - Validators.compose = function (validators) { - if (isBlank(validators)) - return null; - var presentValidators = validators.filter(isPresent); - if (presentValidators.length == 0) - return null; - return function (control) { - return _mergeErrors(_executeValidators(control, presentValidators)); - }; - }; - Validators.composeAsync = function (validators) { - if (isBlank(validators)) - return null; - var presentValidators = validators.filter(isPresent); - if (presentValidators.length == 0) - return null; - return function (control) { - var promises = _executeAsyncValidators(control, presentValidators).map(_convertToPromise); - return Promise.all(promises).then(_mergeErrors); - }; - }; - return Validators; - }()); - function _convertToPromise(obj) { - return isPromise(obj) ? obj : rxjs_operator_toPromise.toPromise.call(obj); - } - function _executeValidators(control, validators) { - return validators.map(function (v) { return v(control); }); - } - function _executeAsyncValidators(control, validators) { - return validators.map(function (v) { return v(control); }); - } - function _mergeErrors(arrayOfErrors) { - var res = arrayOfErrors.reduce(function (res, errors) { - return isPresent(errors) ? StringMapWrapper.merge(res, errors) : res; - }, {}); - return StringMapWrapper.isEmpty(res) ? null : res; - } - /** - * Base class for control directives. - * - * Only used internally in the forms module. - * - * @experimental - */ - var AbstractControlDirective = (function () { - function AbstractControlDirective() { - } - Object.defineProperty(AbstractControlDirective.prototype, "control", { - get: function () { return unimplemented(); }, - enumerable: true, - configurable: true - }); - Object.defineProperty(AbstractControlDirective.prototype, "value", { - get: function () { return isPresent(this.control) ? this.control.value : null; }, - enumerable: true, - configurable: true - }); - Object.defineProperty(AbstractControlDirective.prototype, "valid", { - get: function () { return isPresent(this.control) ? this.control.valid : null; }, - enumerable: true, - configurable: true - }); - Object.defineProperty(AbstractControlDirective.prototype, "errors", { - get: function () { - return isPresent(this.control) ? this.control.errors : null; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(AbstractControlDirective.prototype, "pristine", { - get: function () { return isPresent(this.control) ? this.control.pristine : null; }, - enumerable: true, - configurable: true - }); - Object.defineProperty(AbstractControlDirective.prototype, "dirty", { - get: function () { return isPresent(this.control) ? this.control.dirty : null; }, - enumerable: true, - configurable: true - }); - Object.defineProperty(AbstractControlDirective.prototype, "touched", { - get: function () { return isPresent(this.control) ? this.control.touched : null; }, - enumerable: true, - configurable: true - }); - Object.defineProperty(AbstractControlDirective.prototype, "untouched", { - get: function () { return isPresent(this.control) ? this.control.untouched : null; }, - enumerable: true, - configurable: true - }); - Object.defineProperty(AbstractControlDirective.prototype, "path", { - get: function () { return null; }, - enumerable: true, - configurable: true - }); - return AbstractControlDirective; - }()); /** - * A directive that contains multiple {@link NgControl}s. + * WARNING: this pipe uses the Internationalization API. + * Therefore it is only reliable in Chrome and Opera browsers. For other browsers please use an + * polyfill, for example: [https://github.com/andyearnshaw/Intl.js/]. * - * Only used by the forms module. + * Formats a number as local text. i.e. group sizing and separator and other locale-specific + * configurations are based on the active locale. * - * @experimental + * ### Usage + * + * expression | number[:digitInfo] + * + * where `expression` is a number and `digitInfo` has the following format: + * + * {minIntegerDigits}.{minFractionDigits}-{maxFractionDigits} + * + * - minIntegerDigits is the minimum number of integer digits to use. Defaults to 1. + * - minFractionDigits is the minimum number of digits after fraction. Defaults to 0. + * - maxFractionDigits is the maximum number of digits after fraction. Defaults to 3. + * + * For more information on the acceptable range for each of these numbers and other + * details see your native internationalization library. + * + * ### Example + * + * {@example core/pipes/ts/number_pipe/number_pipe_example.ts region='NumberPipe'} + * + * @stable */ - var ControlContainer = (function (_super) { - __extends(ControlContainer, _super); - function ControlContainer() { - _super.apply(this, arguments); + var DecimalPipe = (function () { + function DecimalPipe(_locale) { + this._locale = _locale; } - Object.defineProperty(ControlContainer.prototype, "formDirective", { - /** - * Get the form to which this container belongs. - */ - get: function () { return null; }, - enumerable: true, - configurable: true - }); - Object.defineProperty(ControlContainer.prototype, "path", { - /** - * Get the path to this container. - */ - get: function () { return null; }, - enumerable: true, - configurable: true - }); - return ControlContainer; - }(AbstractControlDirective)); + DecimalPipe.prototype.transform = function (value, digits) { + if (digits === void 0) { digits = null; } + return formatNumber(DecimalPipe, this._locale, value, NumberFormatStyle.Decimal, digits); + }; + DecimalPipe.decorators = [ + { type: _angular_core.Pipe, args: [{ name: 'number' },] }, + ]; + /** @nocollapse */ + DecimalPipe.ctorParameters = [ + { type: undefined, decorators: [{ type: _angular_core.Inject, args: [_angular_core.LOCALE_ID,] },] }, + ]; + return DecimalPipe; + }()); /** - * @license - * Copyright Google Inc. All Rights Reserved. + * WARNING: this pipe uses the Internationalization API. + * Therefore it is only reliable in Chrome and Opera browsers. For other browsers please use an + * polyfill, for example: [https://github.com/andyearnshaw/Intl.js/]. * - * Use of this source code is governed by an MIT-style license that can be - * found in the LICENSE file at https://angular.io/license + * Formats a number as local percent. + * + * ### Usage + * + * expression | percent[:digitInfo] + * + * For more information about `digitInfo` see {@link DecimalPipe} + * + * ### Example + * + * {@example core/pipes/ts/number_pipe/number_pipe_example.ts region='PercentPipe'} + * + * @stable */ - function normalizeValidator(validator) { - if (validator.validate !== undefined) { - return function (c) { return validator.validate(c); }; - } - else { - return validator; - } - } - function normalizeAsyncValidator(validator) { - if (validator.validate !== undefined) { - return function (c) { return validator.validate(c); }; - } - else { - return validator; - } - } - var NUMBER_VALUE_ACCESSOR = { - provide: NG_VALUE_ACCESSOR, - useExisting: _angular_core.forwardRef(function () { return NumberValueAccessor; }), - multi: true - }; - var NumberValueAccessor = (function () { - function NumberValueAccessor(_renderer, _elementRef) { - this._renderer = _renderer; - this._elementRef = _elementRef; - this.onChange = function (_) { }; - this.onTouched = function () { }; + var PercentPipe = (function () { + function PercentPipe(_locale) { + this._locale = _locale; } - NumberValueAccessor.prototype.writeValue = function (value) { - // The value needs to be normalized for IE9, otherwise it is set to 'null' when null - var normalizedValue = isBlank(value) ? '' : value; - this._renderer.setElementProperty(this._elementRef.nativeElement, 'value', normalizedValue); - }; - NumberValueAccessor.prototype.registerOnChange = function (fn) { - this.onChange = function (value) { fn(value == '' ? null : NumberWrapper.parseFloat(value)); }; - }; - NumberValueAccessor.prototype.registerOnTouched = function (fn) { this.onTouched = fn; }; - return NumberValueAccessor; + PercentPipe.prototype.transform = function (value, digits) { + if (digits === void 0) { digits = null; } + return formatNumber(PercentPipe, this._locale, value, NumberFormatStyle.Percent, digits); + }; + PercentPipe.decorators = [ + { type: _angular_core.Pipe, args: [{ name: 'percent' },] }, + ]; + /** @nocollapse */ + PercentPipe.ctorParameters = [ + { type: undefined, decorators: [{ type: _angular_core.Inject, args: [_angular_core.LOCALE_ID,] },] }, + ]; + return PercentPipe; }()); - /** @nocollapse */ - NumberValueAccessor.decorators = [ - { type: _angular_core.Directive, args: [{ - selector: 'input[type=number][ngControl],input[type=number][ngFormControl],input[type=number][ngModel]', - host: { - '(change)': 'onChange($event.target.value)', - '(input)': 'onChange($event.target.value)', - '(blur)': 'onTouched()' - }, - providers: [NUMBER_VALUE_ACCESSOR] - },] }, - ]; - /** @nocollapse */ - NumberValueAccessor.ctorParameters = [ - { type: _angular_core.Renderer, }, - { type: _angular_core.ElementRef, }, - ]; /** - * A base class that all control directive extend. - * It binds a {@link Control} object to a DOM element. + * WARNING: this pipe uses the Internationalization API. + * Therefore it is only reliable in Chrome and Opera browsers. For other browsers please use an + * polyfill, for example: [https://github.com/andyearnshaw/Intl.js/]. * - * Used internally by Angular forms. * - * @experimental + * Formats a number as local currency. + * + * ### Usage + * + * expression | currency[:currencyCode[:symbolDisplay[:digitInfo]]] + * + * where `currencyCode` is the ISO 4217 currency code, such as "USD" for the US dollar and + * "EUR" for the euro. `symbolDisplay` is a boolean indicating whether to use the currency + * symbol (e.g. $) or the currency code (e.g. USD) in the output. The default for this value + * is `false`. + * For more information about `digitInfo` see {@link DecimalPipe} + * + * ### Example + * + * {@example core/pipes/ts/number_pipe/number_pipe_example.ts region='CurrencyPipe'} + * + * @stable */ - var NgControl = (function (_super) { - __extends(NgControl, _super); - function NgControl() { - var args = []; - for (var _i = 0; _i < arguments.length; _i++) { - args[_i - 0] = arguments[_i]; - } - _super.apply(this, args); - this.name = null; - this.valueAccessor = null; - } - Object.defineProperty(NgControl.prototype, "validator", { - get: function () { return unimplemented(); }, - enumerable: true, - configurable: true - }); - Object.defineProperty(NgControl.prototype, "asyncValidator", { - get: function () { return unimplemented(); }, - enumerable: true, - configurable: true - }); - return NgControl; - }(AbstractControlDirective)); - var RADIO_VALUE_ACCESSOR = { - provide: NG_VALUE_ACCESSOR, - useExisting: _angular_core.forwardRef(function () { return RadioControlValueAccessor; }), - multi: true - }; - var RadioControlRegistry = (function () { - function RadioControlRegistry() { - this._accessors = []; + var CurrencyPipe = (function () { + function CurrencyPipe(_locale) { + this._locale = _locale; } - RadioControlRegistry.prototype.add = function (control, accessor) { - this._accessors.push([control, accessor]); - }; - RadioControlRegistry.prototype.remove = function (accessor) { - var indexToRemove = -1; - for (var i = 0; i < this._accessors.length; ++i) { - if (this._accessors[i][1] === accessor) { - indexToRemove = i; - } - } - ListWrapper.removeAt(this._accessors, indexToRemove); - }; - RadioControlRegistry.prototype.select = function (accessor) { - var _this = this; - this._accessors.forEach(function (c) { - if (_this._isSameGroup(c, accessor) && c[1] !== accessor) { - c[1].fireUncheck(); - } - }); - }; - RadioControlRegistry.prototype._isSameGroup = function (controlPair, accessor) { - return controlPair[0].control.root === accessor._control.control.root && - controlPair[1].name === accessor.name; - }; - return RadioControlRegistry; + CurrencyPipe.prototype.transform = function (value, currencyCode, symbolDisplay, digits) { + if (currencyCode === void 0) { currencyCode = 'USD'; } + if (symbolDisplay === void 0) { symbolDisplay = false; } + if (digits === void 0) { digits = null; } + return formatNumber(CurrencyPipe, this._locale, value, NumberFormatStyle.Currency, digits, currencyCode, symbolDisplay); + }; + CurrencyPipe.decorators = [ + { type: _angular_core.Pipe, args: [{ name: 'currency' },] }, + ]; + /** @nocollapse */ + CurrencyPipe.ctorParameters = [ + { type: undefined, decorators: [{ type: _angular_core.Inject, args: [_angular_core.LOCALE_ID,] },] }, + ]; + return CurrencyPipe; }()); - /** @nocollapse */ - RadioControlRegistry.decorators = [ - { type: _angular_core.Injectable }, - ]; + /** - * The value provided by the forms API for radio buttons. + * Creates a new List or String containing only a subset (slice) of the + * elements. * - * @experimental + * The starting index of the subset to return is specified by the `start` parameter. + * + * The ending index of the subset to return is specified by the optional `end` parameter. + * + * ### Usage + * + * expression | slice:start[:end] + * + * All behavior is based on the expected behavior of the JavaScript API + * Array.prototype.slice() and String.prototype.slice() + * + * Where the input expression is a [List] or [String], and `start` is: + * + * - **a positive integer**: return the item at _start_ index and all items after + * in the list or string expression. + * - **a negative integer**: return the item at _start_ index from the end and all items after + * in the list or string expression. + * - **`|start|` greater than the size of the expression**: return an empty list or string. + * - **`|start|` negative greater than the size of the expression**: return entire list or + * string expression. + * + * and where `end` is: + * + * - **omitted**: return all items until the end of the input + * - **a positive integer**: return all items before _end_ index of the list or string + * expression. + * - **a negative integer**: return all items before _end_ index from the end of the list + * or string expression. + * + * When operating on a [List], the returned list is always a copy even when all + * the elements are being returned. + * + * When operating on a blank value, returns it. + * + * ## List Example + * + * This `ngFor` example: + * + * {@example core/pipes/ts/slice_pipe/slice_pipe_example.ts region='SlicePipe_list'} + * + * produces the following: + * + *
  • b
  • + *
  • c
  • + * + * ## String Examples + * + * {@example core/pipes/ts/slice_pipe/slice_pipe_example.ts region='SlicePipe_string'} + * + * @stable */ - var RadioButtonState = (function () { - function RadioButtonState(checked, value) { - this.checked = checked; - this.value = value; - } - return RadioButtonState; - }()); - var RadioControlValueAccessor = (function () { - function RadioControlValueAccessor(_renderer, _elementRef, _registry, _injector) { - this._renderer = _renderer; - this._elementRef = _elementRef; - this._registry = _registry; - this._injector = _injector; - this.onChange = function () { }; - this.onTouched = function () { }; - } - RadioControlValueAccessor.prototype.ngOnInit = function () { - this._control = this._injector.get(NgControl); - this._registry.add(this._control, this); - }; - RadioControlValueAccessor.prototype.ngOnDestroy = function () { this._registry.remove(this); }; - RadioControlValueAccessor.prototype.writeValue = function (value) { - this._state = value; - if (isPresent(value) && value.checked) { - this._renderer.setElementProperty(this._elementRef.nativeElement, 'checked', true); - } - }; - RadioControlValueAccessor.prototype.registerOnChange = function (fn) { - var _this = this; - this._fn = fn; - this.onChange = function () { - fn(new RadioButtonState(true, _this._state.value)); - _this._registry.select(_this); - }; - }; - RadioControlValueAccessor.prototype.fireUncheck = function () { this._fn(new RadioButtonState(false, this._state.value)); }; - RadioControlValueAccessor.prototype.registerOnTouched = function (fn) { this.onTouched = fn; }; - return RadioControlValueAccessor; - }()); - /** @nocollapse */ - RadioControlValueAccessor.decorators = [ - { type: _angular_core.Directive, args: [{ - selector: 'input[type=radio][ngControl],input[type=radio][ngFormControl],input[type=radio][ngModel]', - host: { '(change)': 'onChange()', '(blur)': 'onTouched()' }, - providers: [RADIO_VALUE_ACCESSOR] - },] }, - ]; - /** @nocollapse */ - RadioControlValueAccessor.ctorParameters = [ - { type: _angular_core.Renderer, }, - { type: _angular_core.ElementRef, }, - { type: RadioControlRegistry, }, - { type: _angular_core.Injector, }, - ]; - /** @nocollapse */ - RadioControlValueAccessor.propDecorators = { - 'name': [{ type: _angular_core.Input },], - }; - var SELECT_VALUE_ACCESSOR = { - provide: NG_VALUE_ACCESSOR, - useExisting: _angular_core.forwardRef(function () { return SelectControlValueAccessor; }), - multi: true - }; - function _buildValueString(id, value) { - if (isBlank(id)) - return "" + value; - if (!isPrimitive(value)) - value = 'Object'; - return StringWrapper.slice(id + ": " + value, 0, 50); - } - function _extractId(valueString) { - return valueString.split(':')[0]; - } - var SelectControlValueAccessor = (function () { - function SelectControlValueAccessor(_renderer, _elementRef) { - this._renderer = _renderer; - this._elementRef = _elementRef; - /** @internal */ - this._optionMap = new Map(); - /** @internal */ - this._idCounter = 0; - this.onChange = function (_) { }; - this.onTouched = function () { }; - } - SelectControlValueAccessor.prototype.writeValue = function (value) { - this.value = value; - var valueString = _buildValueString(this._getOptionId(value), value); - this._renderer.setElementProperty(this._elementRef.nativeElement, 'value', valueString); - }; - SelectControlValueAccessor.prototype.registerOnChange = function (fn) { - var _this = this; - this.onChange = function (valueString) { - _this.value = valueString; - fn(_this._getOptionValue(valueString)); - }; - }; - SelectControlValueAccessor.prototype.registerOnTouched = function (fn) { this.onTouched = fn; }; - /** @internal */ - SelectControlValueAccessor.prototype._registerOption = function () { return (this._idCounter++).toString(); }; - /** @internal */ - SelectControlValueAccessor.prototype._getOptionId = function (value) { - for (var _i = 0, _a = MapWrapper.keys(this._optionMap); _i < _a.length; _i++) { - var id = _a[_i]; - if (looseIdentical(this._optionMap.get(id), value)) - return id; - } - return null; - }; - /** @internal */ - SelectControlValueAccessor.prototype._getOptionValue = function (valueString) { - var value = this._optionMap.get(_extractId(valueString)); - return isPresent(value) ? value : valueString; - }; - return SelectControlValueAccessor; - }()); - /** @nocollapse */ - SelectControlValueAccessor.decorators = [ - { type: _angular_core.Directive, args: [{ - selector: 'select:not([multiple])[ngControl],select:not([multiple])[ngFormControl],select:not([multiple])[ngModel]', - host: { '(change)': 'onChange($event.target.value)', '(blur)': 'onTouched()' }, - providers: [SELECT_VALUE_ACCESSOR] - },] }, - ]; - /** @nocollapse */ - SelectControlValueAccessor.ctorParameters = [ - { type: _angular_core.Renderer, }, - { type: _angular_core.ElementRef, }, - ]; - var NgSelectOption = (function () { - function NgSelectOption(_element, _renderer, _select) { - this._element = _element; - this._renderer = _renderer; - this._select = _select; - if (isPresent(this._select)) - this.id = this._select._registerOption(); - } - Object.defineProperty(NgSelectOption.prototype, "ngValue", { - set: function (value) { - if (this._select == null) - return; - this._select._optionMap.set(this.id, value); - this._setElementValue(_buildValueString(this.id, value)); - this._select.writeValue(this._select.value); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(NgSelectOption.prototype, "value", { - set: function (value) { - this._setElementValue(value); - if (isPresent(this._select)) - this._select.writeValue(this._select.value); - }, - enumerable: true, - configurable: true - }); - /** @internal */ - NgSelectOption.prototype._setElementValue = function (value) { - this._renderer.setElementProperty(this._element.nativeElement, 'value', value); - }; - NgSelectOption.prototype.ngOnDestroy = function () { - if (isPresent(this._select)) { - this._select._optionMap.delete(this.id); - this._select.writeValue(this._select.value); - } - }; - return NgSelectOption; - }()); - /** @nocollapse */ - NgSelectOption.decorators = [ - { type: _angular_core.Directive, args: [{ selector: 'option' },] }, - ]; - /** @nocollapse */ - NgSelectOption.ctorParameters = [ - { type: _angular_core.ElementRef, }, - { type: _angular_core.Renderer, }, - { type: SelectControlValueAccessor, decorators: [{ type: _angular_core.Optional }, { type: _angular_core.Host },] }, - ]; - /** @nocollapse */ - NgSelectOption.propDecorators = { - 'ngValue': [{ type: _angular_core.Input, args: ['ngValue',] },], - 'value': [{ type: _angular_core.Input, args: ['value',] },], - }; - var SELECT_MULTIPLE_VALUE_ACCESSOR = { - provide: NG_VALUE_ACCESSOR, - useExisting: _angular_core.forwardRef(function () { return SelectMultipleControlValueAccessor; }), - multi: true - }; - function _buildValueString$1(id, value) { - if (isBlank(id)) - return "" + value; - if (isString(value)) - value = "'" + value + "'"; - if (!isPrimitive(value)) - value = 'Object'; - return StringWrapper.slice(id + ": " + value, 0, 50); - } - function _extractId$1(valueString) { - return valueString.split(':')[0]; - } - var SelectMultipleControlValueAccessor = (function () { - function SelectMultipleControlValueAccessor() { - /** @internal */ - this._optionMap = new Map(); - /** @internal */ - this._idCounter = 0; - this.onChange = function (_) { }; - this.onTouched = function () { }; + var SlicePipe = (function () { + function SlicePipe() { } - SelectMultipleControlValueAccessor.prototype.writeValue = function (value) { - var _this = this; - this.value = value; - if (value == null) - return; - var values = value; - // convert values to ids - var ids = values.map(function (v) { return _this._getOptionId(v); }); - this._optionMap.forEach(function (opt, o) { opt._setSelected(ids.indexOf(o.toString()) > -1); }); - }; - SelectMultipleControlValueAccessor.prototype.registerOnChange = function (fn) { - var _this = this; - this.onChange = function (_) { - var selected = []; - if (_.hasOwnProperty('selectedOptions')) { - var options = _.selectedOptions; - for (var i = 0; i < options.length; i++) { - var opt = options.item(i); - var val = _this._getOptionValue(opt.value); - selected.push(val); - } - } - else { - var options = _.options; - for (var i = 0; i < options.length; i++) { - var opt = options.item(i); - if (opt.selected) { - var val = _this._getOptionValue(opt.value); - selected.push(val); - } - } - } - fn(selected); - }; - }; - SelectMultipleControlValueAccessor.prototype.registerOnTouched = function (fn) { this.onTouched = fn; }; - /** @internal */ - SelectMultipleControlValueAccessor.prototype._registerOption = function (value) { - var id = (this._idCounter++).toString(); - this._optionMap.set(id, value); - return id; - }; - /** @internal */ - SelectMultipleControlValueAccessor.prototype._getOptionId = function (value) { - for (var _i = 0, _a = MapWrapper.keys(this._optionMap); _i < _a.length; _i++) { - var id = _a[_i]; - if (looseIdentical(this._optionMap.get(id)._value, value)) - return id; - } - return null; - }; - /** @internal */ - SelectMultipleControlValueAccessor.prototype._getOptionValue = function (valueString) { - var opt = this._optionMap.get(_extractId$1(valueString)); - return isPresent(opt) ? opt._value : valueString; - }; - return SelectMultipleControlValueAccessor; - }()); - /** @nocollapse */ - SelectMultipleControlValueAccessor.decorators = [ - { type: _angular_core.Directive, args: [{ - selector: 'select[multiple][ngControl],select[multiple][ngFormControl],select[multiple][ngModel]', - host: { '(change)': 'onChange($event.target)', '(blur)': 'onTouched()' }, - providers: [SELECT_MULTIPLE_VALUE_ACCESSOR] - },] }, - ]; - /** @nocollapse */ - SelectMultipleControlValueAccessor.ctorParameters = []; - var NgSelectMultipleOption = (function () { - function NgSelectMultipleOption(_element, _renderer, _select) { - this._element = _element; - this._renderer = _renderer; - this._select = _select; - if (isPresent(this._select)) { - this.id = this._select._registerOption(this); + SlicePipe.prototype.transform = function (value, start, end) { + if (end === void 0) { end = null; } + if (isBlank(value)) + return value; + if (!this.supports(value)) { + throw new InvalidPipeArgumentError(SlicePipe, value); } - } - Object.defineProperty(NgSelectMultipleOption.prototype, "ngValue", { - set: function (value) { - if (this._select == null) - return; - this._value = value; - this._setElementValue(_buildValueString$1(this.id, value)); - this._select.writeValue(this._select.value); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(NgSelectMultipleOption.prototype, "value", { - set: function (value) { - if (isPresent(this._select)) { - this._value = value; - this._setElementValue(_buildValueString$1(this.id, value)); - this._select.writeValue(this._select.value); - } - else { - this._setElementValue(value); - } - }, - enumerable: true, - configurable: true - }); - /** @internal */ - NgSelectMultipleOption.prototype._setElementValue = function (value) { - this._renderer.setElementProperty(this._element.nativeElement, 'value', value); - }; - /** @internal */ - NgSelectMultipleOption.prototype._setSelected = function (selected) { - this._renderer.setElementProperty(this._element.nativeElement, 'selected', selected); - }; - NgSelectMultipleOption.prototype.ngOnDestroy = function () { - if (isPresent(this._select)) { - this._select._optionMap.delete(this.id); - this._select.writeValue(this._select.value); + if (isString(value)) { + return StringWrapper.slice(value, start, end); } + return ListWrapper.slice(value, start, end); }; - return NgSelectMultipleOption; + SlicePipe.prototype.supports = function (obj) { return isString(obj) || isArray(obj); }; + SlicePipe.decorators = [ + { type: _angular_core.Pipe, args: [{ name: 'slice', pure: false },] }, + ]; + /** @nocollapse */ + SlicePipe.ctorParameters = []; + return SlicePipe; }()); - /** @nocollapse */ - NgSelectMultipleOption.decorators = [ - { type: _angular_core.Directive, args: [{ selector: 'option' },] }, - ]; - /** @nocollapse */ - NgSelectMultipleOption.ctorParameters = [ - { type: _angular_core.ElementRef, }, - { type: _angular_core.Renderer, }, - { type: SelectMultipleControlValueAccessor, decorators: [{ type: _angular_core.Optional }, { type: _angular_core.Host },] }, - ]; - /** @nocollapse */ - NgSelectMultipleOption.propDecorators = { - 'ngValue': [{ type: _angular_core.Input, args: ['ngValue',] },], - 'value': [{ type: _angular_core.Input, args: ['value',] },], - }; - function controlPath(name, parent) { - var p = ListWrapper.clone(parent.path); - p.push(name); - return p; - } - function setUpControl(control, dir) { - if (isBlank(control)) - _throwError(dir, 'Cannot find control with'); - if (isBlank(dir.valueAccessor)) - _throwError(dir, 'No value accessor for form control with'); - control.validator = Validators.compose([control.validator, dir.validator]); - control.asyncValidator = Validators.composeAsync([control.asyncValidator, dir.asyncValidator]); - dir.valueAccessor.writeValue(control.value); - // view -> model - dir.valueAccessor.registerOnChange(function (newValue) { - dir.viewToModelUpdate(newValue); - control.updateValue(newValue, { emitModelToViewChange: false }); - control.markAsDirty(); - }); - // model -> view - control.registerOnChange(function (newValue) { return dir.valueAccessor.writeValue(newValue); }); - // touched - dir.valueAccessor.registerOnTouched(function () { return control.markAsTouched(); }); - } - function setUpControlGroup(control, dir) { - if (isBlank(control)) - _throwError(dir, 'Cannot find control with'); - control.validator = Validators.compose([control.validator, dir.validator]); - control.asyncValidator = Validators.composeAsync([control.asyncValidator, dir.asyncValidator]); - } - function _throwError(dir, message) { - var messageEnd; - if (dir.path.length > 1) { - messageEnd = "path: '" + dir.path.join(' -> ') + "'"; - } - else if (dir.path[0]) { - messageEnd = "name: '" + dir.path + "'"; - } - else { - messageEnd = 'unspecified name'; - } - throw new BaseException(message + " " + messageEnd); - } - function composeValidators(validators) { - return isPresent(validators) ? Validators.compose(validators.map(normalizeValidator)) : null; - } - function composeAsyncValidators(validators) { - return isPresent(validators) ? Validators.composeAsync(validators.map(normalizeAsyncValidator)) : - null; - } - function isPropertyUpdated(changes, viewModel) { - if (!StringMapWrapper.contains(changes, 'model')) - return false; - var change = changes['model']; - if (change.isFirstChange()) - return true; - return !looseIdentical(viewModel, change.currentValue); - } - // TODO: vsavkin remove it once https://github.com/angular/angular/issues/3011 is implemented - function selectValueAccessor(dir, valueAccessors) { - if (isBlank(valueAccessors)) - return null; - var defaultAccessor; - var builtinAccessor; - var customAccessor; - valueAccessors.forEach(function (v) { - if (hasConstructor(v, DefaultValueAccessor)) { - defaultAccessor = v; - } - else if (hasConstructor(v, CheckboxControlValueAccessor) || hasConstructor(v, NumberValueAccessor) || - hasConstructor(v, SelectControlValueAccessor) || - hasConstructor(v, SelectMultipleControlValueAccessor) || - hasConstructor(v, RadioControlValueAccessor)) { - if (isPresent(builtinAccessor)) - _throwError(dir, 'More than one built-in value accessor matches form control with'); - builtinAccessor = v; - } - else { - if (isPresent(customAccessor)) - _throwError(dir, 'More than one custom value accessor matches form control with'); - customAccessor = v; - } - }); - if (isPresent(customAccessor)) - return customAccessor; - if (isPresent(builtinAccessor)) - return builtinAccessor; - if (isPresent(defaultAccessor)) - return defaultAccessor; - _throwError(dir, 'No valid value accessor for form control with'); - return null; - } - var controlGroupProvider = { - provide: ControlContainer, - useExisting: _angular_core.forwardRef(function () { return NgControlGroup; }) - }; - var NgControlGroup = (function (_super) { - __extends(NgControlGroup, _super); - function NgControlGroup(parent, _validators, _asyncValidators) { - _super.call(this); - this._validators = _validators; - this._asyncValidators = _asyncValidators; - this._parent = parent; + + /** + * Implements uppercase transforms to text. + * + * ### Example + * + * {@example core/pipes/ts/lowerupper_pipe/lowerupper_pipe_example.ts region='LowerUpperPipe'} + * + * @stable + */ + var UpperCasePipe = (function () { + function UpperCasePipe() { } - NgControlGroup.prototype.ngOnInit = function () { this.formDirective.addControlGroup(this); }; - NgControlGroup.prototype.ngOnDestroy = function () { this.formDirective.removeControlGroup(this); }; - Object.defineProperty(NgControlGroup.prototype, "control", { - /** - * Get the {@link ControlGroup} backing this binding. - */ - get: function () { return this.formDirective.getControlGroup(this); }, - enumerable: true, - configurable: true - }); - Object.defineProperty(NgControlGroup.prototype, "path", { - /** - * Get the path to this control group. - */ - get: function () { return controlPath(this.name, this._parent); }, - enumerable: true, - configurable: true - }); - Object.defineProperty(NgControlGroup.prototype, "formDirective", { - /** - * Get the {@link Form} to which this group belongs. - */ - get: function () { return this._parent.formDirective; }, - enumerable: true, - configurable: true - }); - Object.defineProperty(NgControlGroup.prototype, "validator", { - get: function () { return composeValidators(this._validators); }, - enumerable: true, - configurable: true - }); - Object.defineProperty(NgControlGroup.prototype, "asyncValidator", { - get: function () { return composeAsyncValidators(this._asyncValidators); }, - enumerable: true, - configurable: true - }); - return NgControlGroup; - }(ControlContainer)); - /** @nocollapse */ - NgControlGroup.decorators = [ - { type: _angular_core.Directive, args: [{ - selector: '[ngControlGroup]', - providers: [controlGroupProvider], - inputs: ['name: ngControlGroup'], - exportAs: 'ngForm' - },] }, - ]; - /** @nocollapse */ - NgControlGroup.ctorParameters = [ - { type: ControlContainer, decorators: [{ type: _angular_core.Host }, { type: _angular_core.SkipSelf },] }, - { type: Array, decorators: [{ type: _angular_core.Optional }, { type: _angular_core.Self }, { type: _angular_core.Inject, args: [NG_VALIDATORS,] },] }, - { type: Array, decorators: [{ type: _angular_core.Optional }, { type: _angular_core.Self }, { type: _angular_core.Inject, args: [NG_ASYNC_VALIDATORS,] },] }, - ]; + UpperCasePipe.prototype.transform = function (value) { + if (isBlank(value)) + return value; + if (!isString(value)) { + throw new InvalidPipeArgumentError(UpperCasePipe, value); + } + return value.toUpperCase(); + }; + UpperCasePipe.decorators = [ + { type: _angular_core.Pipe, args: [{ name: 'uppercase' },] }, + ]; + /** @nocollapse */ + UpperCasePipe.ctorParameters = []; + return UpperCasePipe; + }()); + /** - * Use by directives and components to emit custom Events. + * The `NgClass` directive conditionally adds and removes CSS classes on an HTML element based on + * an expression's evaluation result. * - * ### Examples + * The result of an expression evaluation is interpreted differently depending on type of + * the expression evaluation result: + * - `string` - all the CSS classes listed in a string (space delimited) are added + * - `Array` - all the CSS classes (Array elements) are added + * - `Object` - each key corresponds to a CSS class name while values are interpreted as expressions + * evaluating to `Boolean`. If a given expression evaluates to `true` a corresponding CSS class + * is added - otherwise it is removed. * - * In the following example, `Zippy` alternatively emits `open` and `close` events when its - * title gets clicked: + * While the `NgClass` directive can interpret expressions evaluating to `string`, `Array` + * or `Object`, the `Object`-based version is the most often used and has an advantage of keeping + * all the CSS class names in a template. + * + * ### Example ([live demo](http://plnkr.co/edit/a4YdtmWywhJ33uqfpPPn?p=preview)): * * ``` + * import {Component} from '@angular/core'; + * import {NgClass} from '@angular/common'; + * * @Component({ - * selector: 'zippy', + * selector: 'toggle-button', + * inputs: ['isDisabled'], * template: ` - *
    - *
    Toggle
    - *
    - * - *
    - *
    `}) - * export class Zippy { - * visible: boolean = true; - * @Output() open: EventEmitter = new EventEmitter(); - * @Output() close: EventEmitter = new EventEmitter(); - * - * toggle() { - * this.visible = !this.visible; - * if (this.visible) { - * this.open.emit(null); - * } else { - * this.close.emit(null); + *
    + * Click me! + *
    `, + * styles: [` + * .button { + * width: 120px; + * border: medium solid black; * } - * } - * } - * ``` * - * The events payload can be accessed by the parameter `$event` on the components output event - * handler: + * .active { + * background-color: red; + * } * - * ``` - * - * ``` + * .disabled { + * color: gray; + * border: medium solid gray; + * } + * `], + * directives: [NgClass] + * }) + * class ToggleButton { + * isOn = false; + * isDisabled = false; * - * Uses Rx.Observable but provides an adapter to make it work as specified here: - * https://github.com/jhusain/observable-spec + * toggle(newState) { + * if (!this.isDisabled) { + * this.isOn = newState; + * } + * } + * } + * ``` * - * Once a reference implementation of the spec is available, switch to it. * @stable */ - var EventEmitter$1 = (function (_super) { - __extends(EventEmitter$1, _super); - /** - * Creates an instance of [EventEmitter], which depending on [isAsync], - * delivers events synchronously or asynchronously. - */ - function EventEmitter$1(isAsync) { - if (isAsync === void 0) { isAsync = false; } - _super.call(this); - this.__isAsync = isAsync; - } - EventEmitter$1.prototype.emit = function (value) { _super.prototype.next.call(this, value); }; - /** - * @deprecated - use .emit(value) instead - */ - EventEmitter$1.prototype.next = function (value) { _super.prototype.next.call(this, value); }; - EventEmitter$1.prototype.subscribe = function (generatorOrNext, error, complete) { - var schedulerFn; - var errorFn = function (err) { return null; }; - var completeFn = function () { return null; }; - if (generatorOrNext && typeof generatorOrNext === 'object') { - schedulerFn = this.__isAsync ? function (value /** TODO #9100 */) { - setTimeout(function () { return generatorOrNext.next(value); }); - } : function (value /** TODO #9100 */) { generatorOrNext.next(value); }; - if (generatorOrNext.error) { - errorFn = this.__isAsync ? function (err) { setTimeout(function () { return generatorOrNext.error(err); }); } : - function (err) { generatorOrNext.error(err); }; - } - if (generatorOrNext.complete) { - completeFn = this.__isAsync ? function () { setTimeout(function () { return generatorOrNext.complete(); }); } : - function () { generatorOrNext.complete(); }; - } - } - else { - schedulerFn = this.__isAsync ? function (value /** TODO #9100 */) { - setTimeout(function () { return generatorOrNext(value); }); - } : function (value /** TODO #9100 */) { generatorOrNext(value); }; - if (error) { - errorFn = - this.__isAsync ? function (err) { setTimeout(function () { return error(err); }); } : function (err) { error(err); }; - } - if (complete) { - completeFn = - this.__isAsync ? function () { setTimeout(function () { return complete(); }); } : function () { complete(); }; - } - } - return _super.prototype.subscribe.call(this, schedulerFn, errorFn, completeFn); - }; - return EventEmitter$1; - }(rxjs_Subject.Subject)); - var controlNameBinding = { - provide: NgControl, - useExisting: _angular_core.forwardRef(function () { return NgControlName; }) - }; - var NgControlName = (function (_super) { - __extends(NgControlName, _super); - function NgControlName(_parent, _validators, _asyncValidators, valueAccessors) { - _super.call(this); - this._parent = _parent; - this._validators = _validators; - this._asyncValidators = _asyncValidators; - /** @internal */ - this.update = new EventEmitter$1(); - this._added = false; - this.valueAccessor = selectValueAccessor(this, valueAccessors); - } - NgControlName.prototype.ngOnChanges = function (changes) { - if (!this._added) { - this.formDirective.addControl(this); - this._added = true; - } - if (isPropertyUpdated(changes, this.viewModel)) { - this.viewModel = this.model; - this.formDirective.updateModel(this, this.model); - } - }; - NgControlName.prototype.ngOnDestroy = function () { this.formDirective.removeControl(this); }; - NgControlName.prototype.viewToModelUpdate = function (newValue) { - this.viewModel = newValue; - this.update.emit(newValue); - }; - Object.defineProperty(NgControlName.prototype, "path", { - get: function () { return controlPath(this.name, this._parent); }, - enumerable: true, - configurable: true - }); - Object.defineProperty(NgControlName.prototype, "formDirective", { - get: function () { return this._parent.formDirective; }, - enumerable: true, - configurable: true - }); - Object.defineProperty(NgControlName.prototype, "validator", { - get: function () { return composeValidators(this._validators); }, - enumerable: true, - configurable: true - }); - Object.defineProperty(NgControlName.prototype, "asyncValidator", { - get: function () { - return composeAsyncValidators(this._asyncValidators); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(NgControlName.prototype, "control", { - get: function () { return this.formDirective.getControl(this); }, - enumerable: true, - configurable: true - }); - return NgControlName; - }(NgControl)); - /** @nocollapse */ - NgControlName.decorators = [ - { type: _angular_core.Directive, args: [{ - selector: '[ngControl]', - providers: [controlNameBinding], - inputs: ['name: ngControl', 'model: ngModel'], - outputs: ['update: ngModelChange'], - exportAs: 'ngForm' - },] }, - ]; - /** @nocollapse */ - NgControlName.ctorParameters = [ - { type: ControlContainer, decorators: [{ type: _angular_core.Host }, { type: _angular_core.SkipSelf },] }, - { type: Array, decorators: [{ type: _angular_core.Optional }, { type: _angular_core.Self }, { type: _angular_core.Inject, args: [NG_VALIDATORS,] },] }, - { type: Array, decorators: [{ type: _angular_core.Optional }, { type: _angular_core.Self }, { type: _angular_core.Inject, args: [NG_ASYNC_VALIDATORS,] },] }, - { type: Array, decorators: [{ type: _angular_core.Optional }, { type: _angular_core.Self }, { type: _angular_core.Inject, args: [NG_VALUE_ACCESSOR,] },] }, - ]; - var NgControlStatus = (function () { - function NgControlStatus(cd) { - this._cd = cd; + var NgClass = (function () { + function NgClass(_iterableDiffers, _keyValueDiffers, _ngEl, _renderer) { + this._iterableDiffers = _iterableDiffers; + this._keyValueDiffers = _keyValueDiffers; + this._ngEl = _ngEl; + this._renderer = _renderer; + this._initialClasses = []; } - Object.defineProperty(NgControlStatus.prototype, "ngClassUntouched", { - get: function () { - return isPresent(this._cd.control) ? this._cd.control.untouched : false; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(NgControlStatus.prototype, "ngClassTouched", { - get: function () { - return isPresent(this._cd.control) ? this._cd.control.touched : false; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(NgControlStatus.prototype, "ngClassPristine", { - get: function () { - return isPresent(this._cd.control) ? this._cd.control.pristine : false; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(NgControlStatus.prototype, "ngClassDirty", { - get: function () { - return isPresent(this._cd.control) ? this._cd.control.dirty : false; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(NgControlStatus.prototype, "ngClassValid", { - get: function () { - return isPresent(this._cd.control) ? this._cd.control.valid : false; + Object.defineProperty(NgClass.prototype, "initialClasses", { + set: function (v) { + this._applyInitialClasses(true); + this._initialClasses = isPresent(v) && isString(v) ? v.split(' ') : []; + this._applyInitialClasses(false); + this._applyClasses(this._rawClass, false); }, enumerable: true, configurable: true }); - Object.defineProperty(NgControlStatus.prototype, "ngClassInvalid", { - get: function () { - return isPresent(this._cd.control) ? !this._cd.control.valid : false; + Object.defineProperty(NgClass.prototype, "ngClass", { + set: function (v) { + this._cleanupClasses(this._rawClass); + if (isString(v)) { + v = v.split(' '); + } + this._rawClass = v; + this._iterableDiffer = null; + this._keyValueDiffer = null; + if (isPresent(v)) { + if (isListLikeIterable(v)) { + this._iterableDiffer = this._iterableDiffers.find(v).create(null); + } + else { + this._keyValueDiffer = this._keyValueDiffers.find(v).create(null); + } + } }, enumerable: true, configurable: true }); - return NgControlStatus; - }()); - /** @nocollapse */ - NgControlStatus.decorators = [ - { type: _angular_core.Directive, args: [{ - selector: '[ngControl],[ngModel],[ngFormControl]', - host: { - '[class.ng-untouched]': 'ngClassUntouched', - '[class.ng-touched]': 'ngClassTouched', - '[class.ng-pristine]': 'ngClassPristine', - '[class.ng-dirty]': 'ngClassDirty', - '[class.ng-valid]': 'ngClassValid', - '[class.ng-invalid]': 'ngClassInvalid' - } - },] }, - ]; - /** @nocollapse */ - NgControlStatus.ctorParameters = [ - { type: NgControl, decorators: [{ type: _angular_core.Self },] }, - ]; - /** - * Indicates that a Control is valid, i.e. that no errors exist in the input value. - */ - var VALID = 'VALID'; - /** - * Indicates that a Control is invalid, i.e. that an error exists in the input value. - */ - var INVALID = 'INVALID'; - /** - * Indicates that a Control is pending, i.e. that async validation is occurring and - * errors are not yet available for the input value. - */ - var PENDING = 'PENDING'; - function _find(control, path) { - if (isBlank(path)) - return null; - if (!(path instanceof Array)) { - path = path.split('/'); - } - if (path instanceof Array && ListWrapper.isEmpty(path)) - return null; - return path.reduce(function (v, name) { - if (v instanceof ControlGroup) { - return isPresent(v.controls[name]) ? v.controls[name] : null; + NgClass.prototype.ngDoCheck = function () { + if (isPresent(this._iterableDiffer)) { + var changes = this._iterableDiffer.diff(this._rawClass); + if (isPresent(changes)) { + this._applyIterableChanges(changes); + } } - else if (v instanceof ControlArray) { - var index = name; - return isPresent(v.at(index)) ? v.at(index) : null; + if (isPresent(this._keyValueDiffer)) { + var changes = this._keyValueDiffer.diff(this._rawClass); + if (isPresent(changes)) { + this._applyKeyValueChanges(changes); + } } - else { - return null; + }; + NgClass.prototype._cleanupClasses = function (rawClassVal) { + this._applyClasses(rawClassVal, true); + this._applyInitialClasses(false); + }; + NgClass.prototype._applyKeyValueChanges = function (changes) { + var _this = this; + changes.forEachAddedItem(function (record) { _this._toggleClass(record.key, record.currentValue); }); + changes.forEachChangedItem(function (record) { _this._toggleClass(record.key, record.currentValue); }); + changes.forEachRemovedItem(function (record) { + if (record.previousValue) { + _this._toggleClass(record.key, false); + } + }); + }; + NgClass.prototype._applyIterableChanges = function (changes) { + var _this = this; + changes.forEachAddedItem(function (record) { _this._toggleClass(record.item, true); }); + changes.forEachRemovedItem(function (record) { _this._toggleClass(record.item, false); }); + }; + NgClass.prototype._applyInitialClasses = function (isCleanup) { + var _this = this; + this._initialClasses.forEach(function (className) { return _this._toggleClass(className, !isCleanup); }); + }; + NgClass.prototype._applyClasses = function (rawClassVal, isCleanup) { + var _this = this; + if (isPresent(rawClassVal)) { + if (isArray(rawClassVal)) { + rawClassVal.forEach(function (className) { return _this._toggleClass(className, !isCleanup); }); + } + else if (rawClassVal instanceof Set) { + rawClassVal.forEach(function (className) { return _this._toggleClass(className, !isCleanup); }); + } + else { + StringMapWrapper.forEach(rawClassVal, function (expVal, className) { + if (isPresent(expVal)) + _this._toggleClass(className, !isCleanup); + }); + } } - }, control); - } - function toObservable(r) { - return isPromise(r) ? rxjs_observable_PromiseObservable.PromiseObservable.create(r) : r; - } - /** - * @experimental - */ - var AbstractControl = (function () { - function AbstractControl(validator, asyncValidator) { - this.validator = validator; - this.asyncValidator = asyncValidator; - this._pristine = true; - this._touched = false; - } - Object.defineProperty(AbstractControl.prototype, "value", { - get: function () { return this._value; }, - enumerable: true, - configurable: true - }); - Object.defineProperty(AbstractControl.prototype, "status", { - get: function () { return this._status; }, - enumerable: true, - configurable: true - }); - Object.defineProperty(AbstractControl.prototype, "valid", { - get: function () { return this._status === VALID; }, - enumerable: true, - configurable: true - }); - Object.defineProperty(AbstractControl.prototype, "errors", { - /** - * Returns the errors of this control. - */ - get: function () { return this._errors; }, - enumerable: true, - configurable: true - }); - Object.defineProperty(AbstractControl.prototype, "pristine", { - get: function () { return this._pristine; }, - enumerable: true, - configurable: true - }); - Object.defineProperty(AbstractControl.prototype, "dirty", { - get: function () { return !this.pristine; }, - enumerable: true, - configurable: true - }); - Object.defineProperty(AbstractControl.prototype, "touched", { - get: function () { return this._touched; }, - enumerable: true, - configurable: true - }); - Object.defineProperty(AbstractControl.prototype, "untouched", { - get: function () { return !this._touched; }, - enumerable: true, - configurable: true - }); - Object.defineProperty(AbstractControl.prototype, "valueChanges", { - get: function () { return this._valueChanges; }, + }; + NgClass.prototype._toggleClass = function (className, enabled) { + className = className.trim(); + if (className.length > 0) { + if (className.indexOf(' ') > -1) { + var classes = className.split(/\s+/g); + for (var i = 0, len = classes.length; i < len; i++) { + this._renderer.setElementClass(this._ngEl.nativeElement, classes[i], enabled); + } + } + else { + this._renderer.setElementClass(this._ngEl.nativeElement, className, enabled); + } + } + }; + NgClass.decorators = [ + { type: _angular_core.Directive, args: [{ selector: '[ngClass]' },] }, + ]; + /** @nocollapse */ + NgClass.ctorParameters = [ + { type: _angular_core.IterableDiffers, }, + { type: _angular_core.KeyValueDiffers, }, + { type: _angular_core.ElementRef, }, + { type: _angular_core.Renderer, }, + ]; + NgClass.propDecorators = { + 'initialClasses': [{ type: _angular_core.Input, args: ['class',] },], + 'ngClass': [{ type: _angular_core.Input },], + }; + return NgClass; + }()); + + var NgForRow = (function () { + function NgForRow($implicit, index, count) { + this.$implicit = $implicit; + this.index = index; + this.count = count; + } + Object.defineProperty(NgForRow.prototype, "first", { + get: function () { return this.index === 0; }, enumerable: true, configurable: true }); - Object.defineProperty(AbstractControl.prototype, "statusChanges", { - get: function () { return this._statusChanges; }, + Object.defineProperty(NgForRow.prototype, "last", { + get: function () { return this.index === this.count - 1; }, enumerable: true, configurable: true }); - Object.defineProperty(AbstractControl.prototype, "pending", { - get: function () { return this._status == PENDING; }, + Object.defineProperty(NgForRow.prototype, "even", { + get: function () { return this.index % 2 === 0; }, enumerable: true, configurable: true }); - AbstractControl.prototype.markAsTouched = function () { this._touched = true; }; - AbstractControl.prototype.markAsDirty = function (_a) { - var onlySelf = (_a === void 0 ? {} : _a).onlySelf; - onlySelf = normalizeBool(onlySelf); - this._pristine = false; - if (isPresent(this._parent) && !onlySelf) { - this._parent.markAsDirty({ onlySelf: onlySelf }); - } - }; - AbstractControl.prototype.markAsPending = function (_a) { - var onlySelf = (_a === void 0 ? {} : _a).onlySelf; - onlySelf = normalizeBool(onlySelf); - this._status = PENDING; - if (isPresent(this._parent) && !onlySelf) { - this._parent.markAsPending({ onlySelf: onlySelf }); - } - }; - AbstractControl.prototype.setParent = function (parent) { this._parent = parent; }; - AbstractControl.prototype.updateValueAndValidity = function (_a) { - var _b = _a === void 0 ? {} : _a, onlySelf = _b.onlySelf, emitEvent = _b.emitEvent; - onlySelf = normalizeBool(onlySelf); - emitEvent = isPresent(emitEvent) ? emitEvent : true; - this._updateValue(); - this._errors = this._runValidator(); - this._status = this._calculateStatus(); - if (this._status == VALID || this._status == PENDING) { - this._runAsyncValidator(emitEvent); - } - if (emitEvent) { - this._valueChanges.emit(this._value); - this._statusChanges.emit(this._status); - } - if (isPresent(this._parent) && !onlySelf) { - this._parent.updateValueAndValidity({ onlySelf: onlySelf, emitEvent: emitEvent }); - } - }; - AbstractControl.prototype._runValidator = function () { - return isPresent(this.validator) ? this.validator(this) : null; - }; - AbstractControl.prototype._runAsyncValidator = function (emitEvent) { - var _this = this; - if (isPresent(this.asyncValidator)) { - this._status = PENDING; - this._cancelExistingSubscription(); - var obs = toObservable(this.asyncValidator(this)); - this._asyncValidationSubscription = obs.subscribe({ next: function (res) { return _this.setErrors(res, { emitEvent: emitEvent }); } }); - } - }; - AbstractControl.prototype._cancelExistingSubscription = function () { - if (isPresent(this._asyncValidationSubscription)) { - this._asyncValidationSubscription.unsubscribe(); - } - }; - /** - * Sets errors on a control. - * - * This is used when validations are run not automatically, but manually by the user. - * - * Calling `setErrors` will also update the validity of the parent control. - * - * ## Usage - * - * ``` - * var login = new Control("someLogin"); - * login.setErrors({ - * "notUnique": true - * }); - * - * expect(login.valid).toEqual(false); - * expect(login.errors).toEqual({"notUnique": true}); - * - * login.updateValue("someOtherLogin"); - * - * expect(login.valid).toEqual(true); - * ``` - */ - AbstractControl.prototype.setErrors = function (errors, _a) { - var emitEvent = (_a === void 0 ? {} : _a).emitEvent; - emitEvent = isPresent(emitEvent) ? emitEvent : true; - this._errors = errors; - this._status = this._calculateStatus(); - if (emitEvent) { - this._statusChanges.emit(this._status); - } - if (isPresent(this._parent)) { - this._parent._updateControlsErrors(); - } - }; - AbstractControl.prototype.find = function (path) { return _find(this, path); }; - AbstractControl.prototype.getError = function (errorCode, path) { - if (path === void 0) { path = null; } - var control = isPresent(path) && !ListWrapper.isEmpty(path) ? this.find(path) : this; - if (isPresent(control) && isPresent(control._errors)) { - return StringMapWrapper.get(control._errors, errorCode); - } - else { - return null; - } - }; - AbstractControl.prototype.hasError = function (errorCode, path) { - if (path === void 0) { path = null; } - return isPresent(this.getError(errorCode, path)); - }; - Object.defineProperty(AbstractControl.prototype, "root", { - get: function () { - var x = this; - while (isPresent(x._parent)) { - x = x._parent; - } - return x; - }, + Object.defineProperty(NgForRow.prototype, "odd", { + get: function () { return !this.even; }, enumerable: true, configurable: true }); - /** @internal */ - AbstractControl.prototype._updateControlsErrors = function () { - this._status = this._calculateStatus(); - if (isPresent(this._parent)) { - this._parent._updateControlsErrors(); - } - }; - /** @internal */ - AbstractControl.prototype._initObservables = function () { - this._valueChanges = new EventEmitter$1(); - this._statusChanges = new EventEmitter$1(); - }; - AbstractControl.prototype._calculateStatus = function () { - if (isPresent(this._errors)) - return INVALID; - if (this._anyControlsHaveStatus(PENDING)) - return PENDING; - if (this._anyControlsHaveStatus(INVALID)) - return INVALID; - return VALID; - }; - return AbstractControl; + return NgForRow; }()); /** - * Defines a part of a form that cannot be divided into other controls. `Control`s have values and - * validation state, which is determined by an optional validation function. + * The `NgFor` directive instantiates a template once per item from an iterable. The context for + * each instantiated template inherits from the outer context with the given loop variable set + * to the current item from the iterable. * - * `Control` is one of the three fundamental building blocks used to define forms in Angular, along - * with {@link ControlGroup} and {@link ControlArray}. + * ### Local Variables * - * ## Usage + * `NgFor` provides several exported values that can be aliased to local variables: * - * By default, a `Control` is created for every `` or other form component. - * With {@link NgFormControl} or {@link NgFormModel} an existing {@link Control} can be - * bound to a DOM element instead. This `Control` can be configured with a custom - * validation function. + * * `index` will be set to the current loop iteration for each template context. + * * `first` will be set to a boolean value indicating whether the item is the first one in the + * iteration. + * * `last` will be set to a boolean value indicating whether the item is the last one in the + * iteration. + * * `even` will be set to a boolean value indicating whether this item has an even index. + * * `odd` will be set to a boolean value indicating whether this item has an odd index. * - * ### Example ([live demo](http://plnkr.co/edit/23DESOpbNnBpBHZt1BR4?p=preview)) + * ### Change Propagation * - * @experimental - */ - var Control = (function (_super) { - __extends(Control, _super); - function Control(value, validator, asyncValidator) { - if (value === void 0) { value = null; } - if (validator === void 0) { validator = null; } - if (asyncValidator === void 0) { asyncValidator = null; } - _super.call(this, validator, asyncValidator); - this._value = value; - this.updateValueAndValidity({ onlySelf: true, emitEvent: false }); - this._initObservables(); - } - /** - * Set the value of the control to `value`. - * - * If `onlySelf` is `true`, this change will only affect the validation of this `Control` - * and not its parent component. If `emitEvent` is `true`, this change will cause a - * `valueChanges` event on the `Control` to be emitted. Both of these options default to - * `false`. - * - * If `emitModelToViewChange` is `true`, the view will be notified about the new value - * via an `onChange` event. This is the default behavior if `emitModelToViewChange` is not - * specified. - */ - Control.prototype.updateValue = function (value, _a) { - var _b = _a === void 0 ? {} : _a, onlySelf = _b.onlySelf, emitEvent = _b.emitEvent, emitModelToViewChange = _b.emitModelToViewChange; - emitModelToViewChange = isPresent(emitModelToViewChange) ? emitModelToViewChange : true; - this._value = value; - if (isPresent(this._onChange) && emitModelToViewChange) - this._onChange(this._value); - this.updateValueAndValidity({ onlySelf: onlySelf, emitEvent: emitEvent }); - }; - /** - * @internal - */ - Control.prototype._updateValue = function () { }; - /** - * @internal - */ - Control.prototype._anyControlsHaveStatus = function (status) { return false; }; - /** - * Register a listener for change events. - */ - Control.prototype.registerOnChange = function (fn) { this._onChange = fn; }; - return Control; - }(AbstractControl)); - /** - * Defines a part of a form, of fixed length, that can contain other controls. + * When the contents of the iterator changes, `NgFor` makes the corresponding changes to the DOM: * - * A `ControlGroup` aggregates the values of each {@link Control} in the group. - * The status of a `ControlGroup` depends on the status of its children. - * If one of the controls in a group is invalid, the entire group is invalid. - * Similarly, if a control changes its value, the entire group changes as well. + * * When an item is added, a new instance of the template is added to the DOM. + * * When an item is removed, its template instance is removed from the DOM. + * * When items are reordered, their respective templates are reordered in the DOM. + * * Otherwise, the DOM element for that item will remain the same. * - * `ControlGroup` is one of the three fundamental building blocks used to define forms in Angular, - * along with {@link Control} and {@link ControlArray}. {@link ControlArray} can also contain other - * controls, but is of variable length. + * Angular uses object identity to track insertions and deletions within the iterator and reproduce + * those changes in the DOM. This has important implications for animations and any stateful + * controls + * (such as `` elements which accept user input) that are present. Inserted rows can be + * animated in, deleted rows can be animated out, and unchanged rows retain any unsaved state such + * as user input. * - * ### Example ([live demo](http://plnkr.co/edit/23DESOpbNnBpBHZt1BR4?p=preview)) + * It is possible for the identities of elements in the iterator to change while the data does not. + * This can happen, for example, if the iterator produced from an RPC to the server, and that + * RPC is re-run. Even if the data hasn't changed, the second response will produce objects with + * different identities, and Angular will tear down the entire DOM and rebuild it (as if all old + * elements were deleted and all new elements inserted). This is an expensive operation and should + * be avoided if possible. * - * @experimental - */ - var ControlGroup = (function (_super) { - __extends(ControlGroup, _super); - function ControlGroup(controls, optionals, validator, asyncValidator) { - if (optionals === void 0) { optionals = null; } - if (validator === void 0) { validator = null; } - if (asyncValidator === void 0) { asyncValidator = null; } - _super.call(this, validator, asyncValidator); - this.controls = controls; - this._optionals = isPresent(optionals) ? optionals : {}; - this._initObservables(); - this._setParentForControls(); - this.updateValueAndValidity({ onlySelf: true, emitEvent: false }); - } - /** - * Register a control with the group's list of controls. - */ - ControlGroup.prototype.registerControl = function (name, control) { - this.controls[name] = control; - control.setParent(this); - }; - /** - * Add a control to this group. - */ - ControlGroup.prototype.addControl = function (name, control) { - this.registerControl(name, control); - this.updateValueAndValidity(); - }; - /** - * Remove a control from this group. - */ - ControlGroup.prototype.removeControl = function (name) { - StringMapWrapper.delete(this.controls, name); - this.updateValueAndValidity(); - }; - /** - * Mark the named control as non-optional. - */ - ControlGroup.prototype.include = function (controlName) { - StringMapWrapper.set(this._optionals, controlName, true); - this.updateValueAndValidity(); - }; - /** - * Mark the named control as optional. - */ - ControlGroup.prototype.exclude = function (controlName) { - StringMapWrapper.set(this._optionals, controlName, false); - this.updateValueAndValidity(); - }; - /** - * Check whether there is a control with the given name in the group. - */ - ControlGroup.prototype.contains = function (controlName) { - var c = StringMapWrapper.contains(this.controls, controlName); - return c && this._included(controlName); - }; - /** @internal */ - ControlGroup.prototype._setParentForControls = function () { - var _this = this; - StringMapWrapper.forEach(this.controls, function (control, name) { control.setParent(_this); }); - }; - /** @internal */ - ControlGroup.prototype._updateValue = function () { this._value = this._reduceValue(); }; - /** @internal */ - ControlGroup.prototype._anyControlsHaveStatus = function (status) { - var _this = this; - var res = false; - StringMapWrapper.forEach(this.controls, function (control, name) { - res = res || (_this.contains(name) && control.status == status); - }); - return res; - }; - /** @internal */ - ControlGroup.prototype._reduceValue = function () { - return this._reduceChildren({}, function (acc, control, name) { - acc[name] = control.value; - return acc; - }); - }; - /** @internal */ - ControlGroup.prototype._reduceChildren = function (initValue, fn) { - var _this = this; - var res = initValue; - StringMapWrapper.forEach(this.controls, function (control, name) { - if (_this._included(name)) { - res = fn(res, control, name); - } - }); - return res; - }; - /** @internal */ - ControlGroup.prototype._included = function (controlName) { - var isOptional = StringMapWrapper.contains(this._optionals, controlName); - return !isOptional || StringMapWrapper.get(this._optionals, controlName); - }; - return ControlGroup; - }(AbstractControl)); - /** - * Defines a part of a form, of variable length, that can contain other controls. + * To customize the default tracking algorithm, `NgFor` supports `trackBy` option. + * `trackBy` takes a function which has two arguments: `index` and `item`. + * If `trackBy` is given, Angular tracks changes by the return value of the function. * - * A `ControlArray` aggregates the values of each {@link Control} in the group. - * The status of a `ControlArray` depends on the status of its children. - * If one of the controls in a group is invalid, the entire array is invalid. - * Similarly, if a control changes its value, the entire array changes as well. + * ### Syntax * - * `ControlArray` is one of the three fundamental building blocks used to define forms in Angular, - * along with {@link Control} and {@link ControlGroup}. {@link ControlGroup} can also contain - * other controls, but is of fixed length. + * - `
  • ...
  • ` + * - `
  • ...
  • ` * - * ## Adding or removing controls + * With `