@ -7,7 +7,7 @@
|
||||
*/
|
||||
import {Directive, DoCheck, ElementRef, Input, IterableChanges, IterableDiffer, IterableDiffers, KeyValueChanges, KeyValueDiffer, KeyValueDiffers, Renderer2, ɵisListLikeIterable as isListLikeIterable, ɵstringify as stringify} from '@angular/core';
|
||||
|
||||
type NgClassSupportedTypes = string[] | Set<string>| {[klass: string]: any} | null | undefined;
|
||||
type NgClassSupportedTypes = string[]|Set<string>|{[klass: string]: any}|null|undefined;
|
||||
|
||||
/**
|
||||
* @ngModule CommonModule
|
||||
@ -83,7 +83,7 @@ export class NgClass implements DoCheck {
|
||||
this._applyIterableChanges(iterableChanges);
|
||||
}
|
||||
} else if (this._keyValueDiffer) {
|
||||
const keyValueChanges = this._keyValueDiffer.diff(this._rawClass as{[k: string]: any});
|
||||
const keyValueChanges = this._keyValueDiffer.diff(this._rawClass as {[k: string]: any});
|
||||
if (keyValueChanges) {
|
||||
this._applyKeyValueChanges(keyValueChanges);
|
||||
}
|
||||
@ -105,8 +105,8 @@ export class NgClass implements DoCheck {
|
||||
if (typeof record.item === 'string') {
|
||||
this._toggleClass(record.item, true);
|
||||
} else {
|
||||
throw new Error(
|
||||
`NgClass can only toggle CSS classes expressed as strings, got ${stringify(record.item)}`);
|
||||
throw new Error(`NgClass can only toggle CSS classes expressed as strings, got ${
|
||||
stringify(record.item)}`);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -67,13 +67,13 @@ import {ComponentFactoryResolver, ComponentRef, Directive, Injector, Input, NgMo
|
||||
@Directive({selector: '[ngComponentOutlet]'})
|
||||
export class NgComponentOutlet implements OnChanges, OnDestroy {
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@Input() ngComponentOutlet !: Type<any>;
|
||||
@Input() ngComponentOutlet!: Type<any>;
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@Input() ngComponentOutletInjector !: Injector;
|
||||
@Input() ngComponentOutletInjector!: Injector;
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@Input() ngComponentOutletContent !: any[][];
|
||||
@Input() ngComponentOutletContent!: any[][];
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@Input() ngComponentOutletNgModuleFactory !: NgModuleFactory<any>;
|
||||
@Input() ngComponentOutletNgModuleFactory!: NgModuleFactory<any>;
|
||||
|
||||
private _componentRef: ComponentRef<any>|null = null;
|
||||
private _moduleRef: NgModuleRef<any>|null = null;
|
||||
|
@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {Directive, DoCheck, EmbeddedViewRef, Input, IterableChangeRecord, IterableChanges, IterableDiffer, IterableDiffers, NgIterable, TemplateRef, TrackByFunction, ViewContainerRef, isDevMode} from '@angular/core';
|
||||
import {Directive, DoCheck, EmbeddedViewRef, Input, isDevMode, IterableChangeRecord, IterableChanges, IterableDiffer, IterableDiffers, NgIterable, TemplateRef, TrackByFunction, ViewContainerRef} from '@angular/core';
|
||||
|
||||
/**
|
||||
* @publicApi
|
||||
@ -14,13 +14,21 @@ import {Directive, DoCheck, EmbeddedViewRef, Input, IterableChangeRecord, Iterab
|
||||
export class NgForOfContext<T, U extends NgIterable<T> = NgIterable<T>> {
|
||||
constructor(public $implicit: T, public ngForOf: U, public index: number, public count: number) {}
|
||||
|
||||
get first(): boolean { return this.index === 0; }
|
||||
get first(): boolean {
|
||||
return this.index === 0;
|
||||
}
|
||||
|
||||
get last(): boolean { return this.index === this.count - 1; }
|
||||
get last(): boolean {
|
||||
return this.index === this.count - 1;
|
||||
}
|
||||
|
||||
get even(): boolean { return this.index % 2 === 0; }
|
||||
get even(): boolean {
|
||||
return this.index % 2 === 0;
|
||||
}
|
||||
|
||||
get odd(): boolean { return !this.even; }
|
||||
get odd(): boolean {
|
||||
return !this.even;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -162,13 +170,15 @@ export class NgForOf<T, U extends NgIterable<T> = NgIterable<T>> implements DoCh
|
||||
this._trackByFn = fn;
|
||||
}
|
||||
|
||||
get ngForTrackBy(): TrackByFunction<T> { return this._trackByFn; }
|
||||
get ngForTrackBy(): TrackByFunction<T> {
|
||||
return this._trackByFn;
|
||||
}
|
||||
|
||||
private _ngForOf: U|undefined|null = null;
|
||||
private _ngForOfDirty: boolean = true;
|
||||
private _differ: IterableDiffer<T>|null = null;
|
||||
// TODO(issue/24571): remove '!'.
|
||||
private _trackByFn !: TrackByFunction<T>;
|
||||
private _trackByFn!: TrackByFunction<T>;
|
||||
|
||||
constructor(
|
||||
private _viewContainer: ViewContainerRef,
|
||||
@ -200,8 +210,8 @@ export class NgForOf<T, U extends NgIterable<T> = NgIterable<T>> implements DoCh
|
||||
try {
|
||||
this._differ = this._differs.find(value).create(this.ngForTrackBy);
|
||||
} catch {
|
||||
throw new Error(
|
||||
`Cannot find a differ supporting object '${value}' of type '${getTypeName(value)}'. NgFor only supports binding to Iterables such as Arrays.`);
|
||||
throw new Error(`Cannot find a differ supporting object '${value}' of type '${
|
||||
getTypeName(value)}'. NgFor only supports binding to Iterables such as Arrays.`);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -214,14 +224,14 @@ export class NgForOf<T, U extends NgIterable<T> = NgIterable<T>> implements DoCh
|
||||
private _applyChanges(changes: IterableChanges<T>) {
|
||||
const insertTuples: RecordViewTuple<T, U>[] = [];
|
||||
changes.forEachOperation(
|
||||
(item: IterableChangeRecord<any>, adjustedPreviousIndex: number | null,
|
||||
currentIndex: number | null) => {
|
||||
(item: IterableChangeRecord<any>, adjustedPreviousIndex: number|null,
|
||||
currentIndex: number|null) => {
|
||||
if (item.previousIndex == null) {
|
||||
// NgForOf is never "null" or "undefined" here because the differ detected
|
||||
// that a new item needs to be inserted from the iterable. This implies that
|
||||
// there is an iterable value for "_ngForOf".
|
||||
const view = this._viewContainer.createEmbeddedView(
|
||||
this._template, new NgForOfContext<T, U>(null !, this._ngForOf !, -1, -1),
|
||||
this._template, new NgForOfContext<T, U>(null!, this._ngForOf!, -1, -1),
|
||||
currentIndex === null ? undefined : currentIndex);
|
||||
const tuple = new RecordViewTuple<T, U>(item, view);
|
||||
insertTuples.push(tuple);
|
||||
@ -229,7 +239,7 @@ export class NgForOf<T, U extends NgIterable<T> = NgIterable<T>> implements DoCh
|
||||
this._viewContainer.remove(
|
||||
adjustedPreviousIndex === null ? undefined : adjustedPreviousIndex);
|
||||
} else if (adjustedPreviousIndex !== null) {
|
||||
const view = this._viewContainer.get(adjustedPreviousIndex) !;
|
||||
const view = this._viewContainer.get(adjustedPreviousIndex)!;
|
||||
this._viewContainer.move(view, currentIndex);
|
||||
const tuple = new RecordViewTuple(item, <EmbeddedViewRef<NgForOfContext<T, U>>>view);
|
||||
insertTuples.push(tuple);
|
||||
@ -244,7 +254,7 @@ export class NgForOf<T, U extends NgIterable<T> = NgIterable<T>> implements DoCh
|
||||
const viewRef = <EmbeddedViewRef<NgForOfContext<T, U>>>this._viewContainer.get(i);
|
||||
viewRef.context.index = i;
|
||||
viewRef.context.count = ilen;
|
||||
viewRef.context.ngForOf = this._ngForOf !;
|
||||
viewRef.context.ngForOf = this._ngForOf!;
|
||||
}
|
||||
|
||||
changes.forEachIdentityChange((record: any) => {
|
||||
|
@ -241,11 +241,11 @@ export class NgIf<T = unknown> {
|
||||
* @publicApi
|
||||
*/
|
||||
export class NgIfContext<T = unknown> {
|
||||
public $implicit: T = null !;
|
||||
public ngIf: T = null !;
|
||||
public $implicit: T = null!;
|
||||
public ngIf: T = null!;
|
||||
}
|
||||
|
||||
function assertTemplate(property: string, templateRef: TemplateRef<any>| null): void {
|
||||
function assertTemplate(property: string, templateRef: TemplateRef<any>|null): void {
|
||||
const isTemplateRefOrNull = !!(!templateRef || templateRef.createEmbeddedView);
|
||||
if (!isTemplateRefOrNull) {
|
||||
throw new Error(`${property} must be a TemplateRef, but received '${stringify(templateRef)}'.`);
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
import {Attribute, Directive, Host, Input, TemplateRef, ViewContainerRef} from '@angular/core';
|
||||
|
||||
import {NgLocalization, getPluralCategory} from '../i18n/localization';
|
||||
import {getPluralCategory, NgLocalization} from '../i18n/localization';
|
||||
|
||||
import {SwitchView} from './ng_switch';
|
||||
|
||||
@ -47,9 +47,9 @@ import {SwitchView} from './ng_switch';
|
||||
@Directive({selector: '[ngPlural]'})
|
||||
export class NgPlural {
|
||||
// TODO(issue/24571): remove '!'.
|
||||
private _switchValue !: number;
|
||||
private _switchValue!: number;
|
||||
// TODO(issue/24571): remove '!'.
|
||||
private _activeView !: SwitchView;
|
||||
private _activeView!: SwitchView;
|
||||
private _caseViews: {[k: string]: SwitchView} = {};
|
||||
|
||||
constructor(private _localization: NgLocalization) {}
|
||||
@ -60,7 +60,9 @@ export class NgPlural {
|
||||
this._updateView();
|
||||
}
|
||||
|
||||
addCase(value: string, switchView: SwitchView): void { this._caseViews[value] = switchView; }
|
||||
addCase(value: string, switchView: SwitchView): void {
|
||||
this._caseViews[value] = switchView;
|
||||
}
|
||||
|
||||
private _updateView(): void {
|
||||
this._clearViews();
|
||||
|
@ -62,7 +62,7 @@ export class NgStyle implements DoCheck {
|
||||
|
||||
ngDoCheck() {
|
||||
if (this._differ) {
|
||||
const changes = this._differ.diff(this._ngStyle !);
|
||||
const changes = this._differ.diff(this._ngStyle!);
|
||||
if (changes) {
|
||||
this._applyChanges(changes);
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ export class SwitchView {
|
||||
@Directive({selector: '[ngSwitch]'})
|
||||
export class NgSwitch {
|
||||
// TODO(issue/24571): remove '!'.
|
||||
private _defaultViews !: SwitchView[];
|
||||
private _defaultViews!: SwitchView[];
|
||||
private _defaultUsed = false;
|
||||
private _caseCount = 0;
|
||||
private _lastCaseCheckIndex = 0;
|
||||
@ -120,7 +120,9 @@ export class NgSwitch {
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
_addCase(): number { return this._caseCount++; }
|
||||
_addCase(): number {
|
||||
return this._caseCount++;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
_addDefault(view: SwitchView) {
|
||||
@ -193,8 +195,7 @@ export class NgSwitchCase implements DoCheck {
|
||||
/**
|
||||
* Stores the HTML template to be selected on match.
|
||||
*/
|
||||
@Input()
|
||||
ngSwitchCase: any;
|
||||
@Input() ngSwitchCase: any;
|
||||
|
||||
constructor(
|
||||
viewContainer: ViewContainerRef, templateRef: TemplateRef<Object>,
|
||||
@ -206,7 +207,9 @@ export class NgSwitchCase implements DoCheck {
|
||||
/**
|
||||
* Performs case matching. For internal use only.
|
||||
*/
|
||||
ngDoCheck() { this._view.enforceState(this.ngSwitch._matchCase(this.ngSwitchCase)); }
|
||||
ngDoCheck() {
|
||||
this._view.enforceState(this.ngSwitch._matchCase(this.ngSwitchCase));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -101,7 +101,7 @@ export class NgTemplateOutlet implements OnChanges {
|
||||
|
||||
private _updateExistingContext(ctx: Object): void {
|
||||
for (let propName of Object.keys(ctx)) {
|
||||
(<any>this._viewRef !.context)[propName] = (<any>this.ngTemplateOutletContext)[propName];
|
||||
(<any>this._viewRef!.context)[propName] = (<any>this.ngTemplateOutletContext)[propName];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
let _DOM: DomAdapter = null !;
|
||||
let _DOM: DomAdapter = null!;
|
||||
|
||||
export function getDOM(): DomAdapter {
|
||||
return _DOM;
|
||||
|
@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {FormStyle, FormatWidth, NumberSymbol, Time, TranslationWidth, getLocaleDateFormat, getLocaleDateTimeFormat, getLocaleDayNames, getLocaleDayPeriods, getLocaleEraNames, getLocaleExtraDayPeriodRules, getLocaleExtraDayPeriods, getLocaleId, getLocaleMonthNames, getLocaleNumberSymbol, getLocaleTimeFormat} from './locale_data_api';
|
||||
import {FormatWidth, FormStyle, getLocaleDateFormat, getLocaleDateTimeFormat, getLocaleDayNames, getLocaleDayPeriods, getLocaleEraNames, getLocaleExtraDayPeriodRules, getLocaleExtraDayPeriods, getLocaleId, getLocaleMonthNames, getLocaleNumberSymbol, getLocaleTimeFormat, NumberSymbol, Time, TranslationWidth} from './locale_data_api';
|
||||
|
||||
export const ISO8601_DATE_REGEX =
|
||||
/^(\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d+))?)?)?(Z|([+-])(\d\d):?(\d\d))?)?$/;
|
||||
@ -62,7 +62,7 @@ enum TranslationType {
|
||||
* @publicApi
|
||||
*/
|
||||
export function formatDate(
|
||||
value: string | number | Date, format: string, locale: string, timezone?: string): string {
|
||||
value: string|number|Date, format: string, locale: string, timezone?: string): string {
|
||||
let date = toDate(value);
|
||||
const namedFormat = getNamedFormat(locale, format);
|
||||
format = namedFormat || format;
|
||||
@ -278,7 +278,7 @@ function getDateTranslation(
|
||||
const rules = getLocaleExtraDayPeriodRules(locale);
|
||||
const dayPeriods = getLocaleExtraDayPeriods(locale, form, width);
|
||||
let result;
|
||||
rules.forEach((rule: Time | [Time, Time], index: number) => {
|
||||
rules.forEach((rule: Time|[Time, Time], index: number) => {
|
||||
if (Array.isArray(rule)) {
|
||||
// morning, afternoon, evening, night
|
||||
const {hours: hoursFrom, minutes: minutesFrom} = rule[0];
|
||||
@ -652,7 +652,7 @@ function convertTimezoneToLocal(date: Date, timezone: string, reverse: boolean):
|
||||
*
|
||||
* Throws if unable to convert to a date.
|
||||
*/
|
||||
export function toDate(value: string | number | Date): Date {
|
||||
export function toDate(value: string|number|Date): Date {
|
||||
if (isDate(value)) {
|
||||
return value;
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {NumberFormatStyle, NumberSymbol, getLocaleNumberFormat, getLocaleNumberSymbol, getNumberOfCurrencyDigits} from './locale_data_api';
|
||||
import {getLocaleNumberFormat, getLocaleNumberSymbol, getNumberOfCurrencyDigits, NumberFormatStyle, NumberSymbol} from './locale_data_api';
|
||||
|
||||
export const NUMBER_FORMAT_REGEXP = /^(\d+)?\.((\d+)(-(\d+))?)?$/;
|
||||
const MAX_DIGITS = 22;
|
||||
@ -153,7 +153,7 @@ export function formatCurrency(
|
||||
const format = getLocaleNumberFormat(locale, NumberFormatStyle.Currency);
|
||||
const pattern = parseNumberFormat(format, getLocaleNumberSymbol(locale, NumberSymbol.MinusSign));
|
||||
|
||||
pattern.minFrac = getNumberOfCurrencyDigits(currencyCode !);
|
||||
pattern.minFrac = getNumberOfCurrencyDigits(currencyCode!);
|
||||
pattern.maxFrac = pattern.minFrac;
|
||||
|
||||
const res = formatNumberToLocaleString(
|
||||
@ -392,8 +392,8 @@ function parseNumber(num: number): ParsedNumber {
|
||||
*/
|
||||
function roundNumber(parsedNumber: ParsedNumber, minFrac: number, maxFrac: number) {
|
||||
if (minFrac > maxFrac) {
|
||||
throw new Error(
|
||||
`The minimum number of digits after fraction (${minFrac}) is higher than the maximum (${maxFrac}).`);
|
||||
throw new Error(`The minimum number of digits after fraction (${
|
||||
minFrac}) is higher than the maximum (${maxFrac}).`);
|
||||
}
|
||||
|
||||
let digits = parsedNumber.digits;
|
||||
|
@ -16,6 +16,6 @@ import {ɵregisterLocaleData} from '@angular/core';
|
||||
*
|
||||
* @publicApi
|
||||
*/
|
||||
export function registerLocaleData(data: any, localeId?: string | any, extraData?: any): void {
|
||||
export function registerLocaleData(data: any, localeId?: string|any, extraData?: any): void {
|
||||
return ɵregisterLocaleData(data, localeId, extraData);
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {ɵCurrencyIndex, ɵExtraLocaleDataIndex, ɵLocaleDataIndex, ɵfindLocaleData, ɵgetLocaleCurrencyCode, ɵgetLocalePluralCase} from '@angular/core';
|
||||
import {ɵCurrencyIndex, ɵExtraLocaleDataIndex, ɵfindLocaleData, ɵgetLocaleCurrencyCode, ɵgetLocalePluralCase, ɵLocaleDataIndex} from '@angular/core';
|
||||
|
||||
import {CURRENCIES_EN, CurrenciesSymbols} from './currencies';
|
||||
|
||||
@ -235,9 +235,9 @@ export function getLocaleId(locale: string): string {
|
||||
export function getLocaleDayPeriods(
|
||||
locale: string, formStyle: FormStyle, width: TranslationWidth): [string, string] {
|
||||
const data = ɵfindLocaleData(locale);
|
||||
const amPmData = <[
|
||||
string, string
|
||||
][][]>[data[ɵLocaleDataIndex.DayPeriodsFormat], data[ɵLocaleDataIndex.DayPeriodsStandalone]];
|
||||
const amPmData = <[string, string][][]>[
|
||||
data[ɵLocaleDataIndex.DayPeriodsFormat], data[ɵLocaleDataIndex.DayPeriodsStandalone]
|
||||
];
|
||||
const amPm = getLastDefinedValue(amPmData, formStyle);
|
||||
return getLastDefinedValue(amPm, width);
|
||||
}
|
||||
@ -509,8 +509,9 @@ export const getLocalePluralCase: (locale: string) => ((value: number) => Plural
|
||||
|
||||
function checkFullData(data: any) {
|
||||
if (!data[ɵLocaleDataIndex.ExtraData]) {
|
||||
throw new Error(
|
||||
`Missing extra locale data for the locale "${data[ɵLocaleDataIndex.LocaleId]}". Use "registerLocaleData" to load new data. See the "I18n guide" on angular.io to know more.`);
|
||||
throw new Error(`Missing extra locale data for the locale "${
|
||||
data[ɵLocaleDataIndex
|
||||
.LocaleId]}". Use "registerLocaleData" to load new data. See the "I18n guide" on angular.io to know more.`);
|
||||
}
|
||||
}
|
||||
|
||||
@ -536,11 +537,11 @@ function checkFullData(data: any) {
|
||||
*
|
||||
* @publicApi
|
||||
*/
|
||||
export function getLocaleExtraDayPeriodRules(locale: string): (Time | [Time, Time])[] {
|
||||
export function getLocaleExtraDayPeriodRules(locale: string): (Time|[Time, Time])[] {
|
||||
const data = ɵfindLocaleData(locale);
|
||||
checkFullData(data);
|
||||
const rules = data[ɵLocaleDataIndex.ExtraData][ɵExtraLocaleDataIndex.ExtraDayPeriodsRules] || [];
|
||||
return rules.map((rule: string | [string, string]) => {
|
||||
return rules.map((rule: string|[string, string]) => {
|
||||
if (typeof rule === 'string') {
|
||||
return extractTime(rule);
|
||||
}
|
||||
@ -570,8 +571,8 @@ export function getLocaleExtraDayPeriods(
|
||||
const data = ɵfindLocaleData(locale);
|
||||
checkFullData(data);
|
||||
const dayPeriodsData = <string[][][]>[
|
||||
data[ɵLocaleDataIndex.ExtraData][ɵExtraLocaleDataIndex.ExtraDayPeriodFormats],
|
||||
data[ɵLocaleDataIndex.ExtraData][ɵExtraLocaleDataIndex.ExtraDayPeriodStandalone]
|
||||
data[ɵLocaleDataIndex.ExtraData][ɵExtraLocaleDataIndex.ExtraDayPeriodFormats],
|
||||
data[ɵLocaleDataIndex.ExtraData][ɵExtraLocaleDataIndex.ExtraDayPeriodStandalone]
|
||||
];
|
||||
const dayPeriods = getLastDefinedValue(dayPeriodsData, formStyle) || [];
|
||||
return getLastDefinedValue(dayPeriods, width) || [];
|
||||
@ -646,7 +647,7 @@ function extractTime(time: string): Time {
|
||||
*
|
||||
* @publicApi
|
||||
*/
|
||||
export function getCurrencySymbol(code: string, format: 'wide' | 'narrow', locale = 'en'): string {
|
||||
export function getCurrencySymbol(code: string, format: 'wide'|'narrow', locale = 'en'): string {
|
||||
const currency = getLocaleCurrencies(locale)[code] || CURRENCIES_EN[code] || [];
|
||||
const symbolNarrow = currency[ɵCurrencyIndex.SymbolNarrow];
|
||||
|
||||
|
@ -7,7 +7,8 @@
|
||||
*/
|
||||
|
||||
import {Inject, Injectable, LOCALE_ID} from '@angular/core';
|
||||
import {Plural, getLocalePluralCase} from './locale_data_api';
|
||||
|
||||
import {getLocalePluralCase, Plural} from './locale_data_api';
|
||||
|
||||
|
||||
/**
|
||||
@ -51,7 +52,9 @@ export function getPluralCategory(
|
||||
*/
|
||||
@Injectable()
|
||||
export class NgLocaleLocalization extends NgLocalization {
|
||||
constructor(@Inject(LOCALE_ID) protected locale: string) { super(); }
|
||||
constructor(@Inject(LOCALE_ID) protected locale: string) {
|
||||
super();
|
||||
}
|
||||
|
||||
getPluralCategory(value: any, locale?: string): string {
|
||||
const plural = getLocalePluralCase(locale || this.locale)(value);
|
||||
|
@ -48,7 +48,9 @@ export class HashLocationStrategy extends LocationStrategy {
|
||||
this._platformLocation.onHashChange(fn);
|
||||
}
|
||||
|
||||
getBaseHref(): string { return this._baseHref; }
|
||||
getBaseHref(): string {
|
||||
return this._baseHref;
|
||||
}
|
||||
|
||||
path(includeHash: boolean = false): string {
|
||||
// the hash value is always prefixed with a `#`
|
||||
@ -80,7 +82,11 @@ export class HashLocationStrategy extends LocationStrategy {
|
||||
this._platformLocation.replaceState(state, title, url);
|
||||
}
|
||||
|
||||
forward(): void { this._platformLocation.forward(); }
|
||||
forward(): void {
|
||||
this._platformLocation.forward();
|
||||
}
|
||||
|
||||
back(): void { this._platformLocation.back(); }
|
||||
back(): void {
|
||||
this._platformLocation.back();
|
||||
}
|
||||
}
|
||||
|
@ -97,7 +97,9 @@ export class Location {
|
||||
* Reports the current state of the location history.
|
||||
* @returns The current value of the `history.state` object.
|
||||
*/
|
||||
getState(): unknown { return this._platformLocation.getState(); }
|
||||
getState(): unknown {
|
||||
return this._platformLocation.getState();
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizes the given path and compares to the current normalized path.
|
||||
@ -173,12 +175,16 @@ export class Location {
|
||||
/**
|
||||
* Navigates forward in the platform's history.
|
||||
*/
|
||||
forward(): void { this._platformStrategy.forward(); }
|
||||
forward(): void {
|
||||
this._platformStrategy.forward();
|
||||
}
|
||||
|
||||
/**
|
||||
* Navigates back in the platform's history.
|
||||
*/
|
||||
back(): void { this._platformStrategy.back(); }
|
||||
back(): void {
|
||||
this._platformStrategy.back();
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a URL change listener. Use to catch updates performed by the Angular
|
||||
@ -188,7 +194,9 @@ export class Location {
|
||||
*/
|
||||
onUrlChange(fn: (url: string, state: unknown) => void) {
|
||||
this._urlChangeListeners.push(fn);
|
||||
this.subscribe(v => { this._notifyUrlChangeListeners(v.url, v.state); });
|
||||
this.subscribe(v => {
|
||||
this._notifyUrlChangeListeners(v.url, v.state);
|
||||
});
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
|
@ -126,9 +126,13 @@ export class PathLocationStrategy extends LocationStrategy {
|
||||
this._platformLocation.onHashChange(fn);
|
||||
}
|
||||
|
||||
getBaseHref(): string { return this._baseHref; }
|
||||
getBaseHref(): string {
|
||||
return this._baseHref;
|
||||
}
|
||||
|
||||
prepareExternalUrl(internal: string): string { return joinWithSlash(this._baseHref, internal); }
|
||||
prepareExternalUrl(internal: string): string {
|
||||
return joinWithSlash(this._baseHref, internal);
|
||||
}
|
||||
|
||||
path(includeHash: boolean = false): string {
|
||||
const pathname =
|
||||
@ -147,7 +151,11 @@ export class PathLocationStrategy extends LocationStrategy {
|
||||
this._platformLocation.replaceState(state, title, externalUrl);
|
||||
}
|
||||
|
||||
forward(): void { this._platformLocation.forward(); }
|
||||
forward(): void {
|
||||
this._platformLocation.forward();
|
||||
}
|
||||
|
||||
back(): void { this._platformLocation.back(); }
|
||||
back(): void {
|
||||
this._platformLocation.back();
|
||||
}
|
||||
}
|
||||
|
@ -86,7 +86,9 @@ export interface LocationChangeEvent {
|
||||
/**
|
||||
* @publicApi
|
||||
*/
|
||||
export interface LocationChangeListener { (event: LocationChangeEvent): any; }
|
||||
export interface LocationChangeListener {
|
||||
(event: LocationChangeEvent): any;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -101,8 +103,8 @@ export interface LocationChangeListener { (event: LocationChangeEvent): any; }
|
||||
useFactory: createBrowserPlatformLocation,
|
||||
})
|
||||
export class BrowserPlatformLocation extends PlatformLocation {
|
||||
public readonly location !: Location;
|
||||
private _history !: History;
|
||||
public readonly location!: Location;
|
||||
private _history!: History;
|
||||
|
||||
constructor(@Inject(DOCUMENT) private _doc: any) {
|
||||
super();
|
||||
@ -112,11 +114,13 @@ export class BrowserPlatformLocation extends PlatformLocation {
|
||||
// This is moved to its own method so that `MockPlatformLocationStrategy` can overwrite it
|
||||
/** @internal */
|
||||
_init() {
|
||||
(this as{location: Location}).location = getDOM().getLocation();
|
||||
(this as {location: Location}).location = getDOM().getLocation();
|
||||
this._history = getDOM().getHistory();
|
||||
}
|
||||
|
||||
getBaseHrefFromDOM(): string { return getDOM().getBaseHref(this._doc) !; }
|
||||
getBaseHrefFromDOM(): string {
|
||||
return getDOM().getBaseHref(this._doc)!;
|
||||
}
|
||||
|
||||
onPopState(fn: LocationChangeListener): void {
|
||||
getDOM().getGlobalEventTarget(this._doc, 'window').addEventListener('popstate', fn, false);
|
||||
@ -126,14 +130,30 @@ export class BrowserPlatformLocation extends PlatformLocation {
|
||||
getDOM().getGlobalEventTarget(this._doc, 'window').addEventListener('hashchange', fn, false);
|
||||
}
|
||||
|
||||
get href(): string { return this.location.href; }
|
||||
get protocol(): string { return this.location.protocol; }
|
||||
get hostname(): string { return this.location.hostname; }
|
||||
get port(): string { return this.location.port; }
|
||||
get pathname(): string { return this.location.pathname; }
|
||||
get search(): string { return this.location.search; }
|
||||
get hash(): string { return this.location.hash; }
|
||||
set pathname(newPath: string) { this.location.pathname = newPath; }
|
||||
get href(): string {
|
||||
return this.location.href;
|
||||
}
|
||||
get protocol(): string {
|
||||
return this.location.protocol;
|
||||
}
|
||||
get hostname(): string {
|
||||
return this.location.hostname;
|
||||
}
|
||||
get port(): string {
|
||||
return this.location.port;
|
||||
}
|
||||
get pathname(): string {
|
||||
return this.location.pathname;
|
||||
}
|
||||
get search(): string {
|
||||
return this.location.search;
|
||||
}
|
||||
get hash(): string {
|
||||
return this.location.hash;
|
||||
}
|
||||
set pathname(newPath: string) {
|
||||
this.location.pathname = newPath;
|
||||
}
|
||||
|
||||
pushState(state: any, title: string, url: string): void {
|
||||
if (supportsState()) {
|
||||
@ -151,11 +171,17 @@ export class BrowserPlatformLocation extends PlatformLocation {
|
||||
}
|
||||
}
|
||||
|
||||
forward(): void { this._history.forward(); }
|
||||
forward(): void {
|
||||
this._history.forward();
|
||||
}
|
||||
|
||||
back(): void { this._history.back(); }
|
||||
back(): void {
|
||||
this._history.back();
|
||||
}
|
||||
|
||||
getState(): unknown { return this._history.state; }
|
||||
getState(): unknown {
|
||||
return this._history.state;
|
||||
}
|
||||
}
|
||||
|
||||
export function supportsState(): boolean {
|
||||
|
@ -19,17 +19,28 @@ interface SubscriptionStrategy {
|
||||
|
||||
class ObservableStrategy implements SubscriptionStrategy {
|
||||
createSubscription(async: Observable<any>, updateLatestValue: any): SubscriptionLike {
|
||||
return async.subscribe({next: updateLatestValue, error: (e: any) => { throw e; }});
|
||||
return async.subscribe({
|
||||
next: updateLatestValue,
|
||||
error: (e: any) => {
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
dispose(subscription: SubscriptionLike): void { subscription.unsubscribe(); }
|
||||
dispose(subscription: SubscriptionLike): void {
|
||||
subscription.unsubscribe();
|
||||
}
|
||||
|
||||
onDestroy(subscription: SubscriptionLike): void { subscription.unsubscribe(); }
|
||||
onDestroy(subscription: SubscriptionLike): void {
|
||||
subscription.unsubscribe();
|
||||
}
|
||||
}
|
||||
|
||||
class PromiseStrategy implements SubscriptionStrategy {
|
||||
createSubscription(async: Promise<any>, updateLatestValue: (v: any) => any): Promise<any> {
|
||||
return async.then(updateLatestValue, e => { throw e; });
|
||||
return async.then(updateLatestValue, e => {
|
||||
throw e;
|
||||
});
|
||||
}
|
||||
|
||||
dispose(subscription: Promise<any>): void {}
|
||||
@ -74,7 +85,7 @@ export class AsyncPipe implements OnDestroy, PipeTransform {
|
||||
|
||||
private _subscription: SubscriptionLike|Promise<any>|null = null;
|
||||
private _obj: Observable<any>|Promise<any>|EventEmitter<any>|null = null;
|
||||
private _strategy: SubscriptionStrategy = null !;
|
||||
private _strategy: SubscriptionStrategy = null!;
|
||||
|
||||
constructor(private _ref: ChangeDetectorRef) {}
|
||||
|
||||
@ -130,7 +141,7 @@ export class AsyncPipe implements OnDestroy, PipeTransform {
|
||||
}
|
||||
|
||||
private _dispose(): void {
|
||||
this._strategy.dispose(this._subscription !);
|
||||
this._strategy.dispose(this._subscription!);
|
||||
this._latestValue = null;
|
||||
this._latestReturnedValue = null;
|
||||
this._subscription = null;
|
||||
|
@ -7,7 +7,9 @@
|
||||
*/
|
||||
|
||||
import {Pipe, PipeTransform} from '@angular/core';
|
||||
import {NgLocalization, getPluralCategory} from '../i18n/localization';
|
||||
|
||||
import {getPluralCategory, NgLocalization} from '../i18n/localization';
|
||||
|
||||
import {invalidPipeArgumentError} from './invalid_pipe_argument_error';
|
||||
|
||||
const _INTERPOLATION_REGEXP: RegExp = /#/g;
|
||||
|
@ -26,11 +26,11 @@ export {
|
||||
CurrencyPipe,
|
||||
DatePipe,
|
||||
DecimalPipe,
|
||||
KeyValue,
|
||||
KeyValuePipe,
|
||||
I18nPluralPipe,
|
||||
I18nSelectPipe,
|
||||
JsonPipe,
|
||||
KeyValue,
|
||||
KeyValuePipe,
|
||||
LowerCasePipe,
|
||||
PercentPipe,
|
||||
SlicePipe,
|
||||
|
@ -28,5 +28,7 @@ export class JsonPipe implements PipeTransform {
|
||||
/**
|
||||
* @param value A value of any type to convert into a JSON-format string.
|
||||
*/
|
||||
transform(value: any): string { return JSON.stringify(value, null, 2); }
|
||||
transform(value: any): string {
|
||||
return JSON.stringify(value, null, 2);
|
||||
}
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ export interface KeyValue<K, V> {
|
||||
export class KeyValuePipe implements PipeTransform {
|
||||
constructor(private readonly differs: KeyValueDiffers) {}
|
||||
|
||||
private differ !: KeyValueDiffer<any, any>;
|
||||
private differ!: KeyValueDiffer<any, any>;
|
||||
private keyValues: Array<KeyValue<any, any>> = [];
|
||||
|
||||
transform<K, V>(input: null, compareFn?: (a: KeyValue<K, V>, b: KeyValue<K, V>) => number): null;
|
||||
@ -90,7 +90,7 @@ export class KeyValuePipe implements PipeTransform {
|
||||
if (differChanges) {
|
||||
this.keyValues = [];
|
||||
differChanges.forEachItem((r: KeyValueChangeRecord<K, V>) => {
|
||||
this.keyValues.push(makeKeyValuePair(r.key, r.currentValue !));
|
||||
this.keyValues.push(makeKeyValuePair(r.key, r.currentValue!));
|
||||
});
|
||||
this.keyValues.sort(compareFn);
|
||||
}
|
||||
|
@ -253,7 +253,7 @@ function isEmpty(value: any): boolean {
|
||||
/**
|
||||
* Transforms a string into a number (if needed).
|
||||
*/
|
||||
function strToNumber(value: number | string): number {
|
||||
function strToNumber(value: number|string): number {
|
||||
// Convert strings to numbers
|
||||
if (typeof value === 'string' && !isNaN(Number(value) - parseFloat(value))) {
|
||||
return Number(value);
|
||||
|
@ -75,5 +75,7 @@ export class SlicePipe implements PipeTransform {
|
||||
return value.slice(start, end);
|
||||
}
|
||||
|
||||
private supports(obj: any): boolean { return typeof obj === 'string' || Array.isArray(obj); }
|
||||
private supports(obj: any): boolean {
|
||||
return typeof obj === 'string' || Array.isArray(obj);
|
||||
}
|
||||
}
|
||||
|
@ -186,7 +186,9 @@ export class NullViewportScroller implements ViewportScroller {
|
||||
/**
|
||||
* Empty implementation
|
||||
*/
|
||||
getScrollPosition(): [number, number] { return [0, 0]; }
|
||||
getScrollPosition(): [number, number] {
|
||||
return [0, 0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty implementation
|
||||
|
Reference in New Issue
Block a user