From 5776f76ac979caa6f9e0668ea9c15c3e7c3c2e8b Mon Sep 17 00:00:00 2001 From: Manuel Mtz-Almeida Date: Tue, 18 Apr 2017 20:52:17 +0200 Subject: [PATCH] fix(base-input): inputUpdated() is triggered when initialized --- src/components/datetime/datetime.ts | 9 ++-- src/components/datetime/test/datetime.spec.ts | 16 +++--- src/components/select/select.ts | 11 ++-- src/util/base-input.ts | 13 ++++- src/util/input-tester.ts | 53 ++++++++++--------- 5 files changed, 53 insertions(+), 49 deletions(-) diff --git a/src/components/datetime/datetime.ts b/src/components/datetime/datetime.ts index d37affee136..ac1e09fa1d5 100644 --- a/src/components/datetime/datetime.ts +++ b/src/components/datetime/datetime.ts @@ -1,4 +1,4 @@ -import { AfterContentInit, Component, ElementRef, EventEmitter, forwardRef, HostListener, Input, OnDestroy, Optional, Output, Renderer, ViewEncapsulation } from '@angular/core'; +import { AfterViewInit, Component, ElementRef, EventEmitter, forwardRef, HostListener, Input, OnDestroy, Optional, Output, Renderer, ViewEncapsulation } from '@angular/core'; import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'; import { Config } from '../../config/config'; @@ -273,7 +273,7 @@ export const DATETIME_VALUE_ACCESSOR: any = { providers: [DATETIME_VALUE_ACCESSOR], encapsulation: ViewEncapsulation.None, }) -export class DateTime extends BaseInput implements AfterContentInit, ControlValueAccessor, OnDestroy { +export class DateTime extends BaseInput implements AfterViewInit, ControlValueAccessor, OnDestroy { _text: string = ''; _min: DateTimeData; @@ -431,7 +431,7 @@ export class DateTime extends BaseInput implements AfterContentIni /** * @hidden */ - ngAfterContentInit() { + ngAfterViewInit() { // first see if locale names were provided in the inputs // then check to see if they're in the config // if neither were provided then it will use default English names @@ -439,8 +439,7 @@ export class DateTime extends BaseInput implements AfterContentIni (this)._locale[type] = convertToArrayOfStrings(isPresent((this)[type]) ? (this)[type] : this._config.get(type), type); }); - // update how the datetime value is displayed as formatted text - this.updateText(); + this._initialize(); } /** diff --git a/src/components/datetime/test/datetime.spec.ts b/src/components/datetime/test/datetime.spec.ts index 847d8c32f73..6e2f52d0631 100644 --- a/src/components/datetime/test/datetime.spec.ts +++ b/src/components/datetime/test/datetime.spec.ts @@ -144,7 +144,7 @@ describe('DateTime', () => { describe('writeValue', () => { it('should updateText with default MMM D, YYYY when no displayFormat or pickerFormat', zoned(() => { - datetime.ngAfterContentInit(); + datetime.ngAfterViewInit(); datetime.writeValue('1994-12-15T13:47:20.789Z'); expect(datetime._text).toEqual('Dec 15, 1994'); @@ -152,7 +152,7 @@ describe('DateTime', () => { it('should updateText with pickerFormat when no displayFormat', zoned(() => { datetime.pickerFormat = 'YYYY'; - datetime.ngAfterContentInit(); + datetime.ngAfterViewInit(); datetime.writeValue('1994-12-15T13:47:20.789Z'); expect(datetime._text).toEqual('1994'); @@ -160,7 +160,7 @@ describe('DateTime', () => { it('should updateText with displayFormat when no pickerFormat', zoned(() => { datetime.displayFormat = 'YYYY'; - datetime.ngAfterContentInit(); + datetime.ngAfterViewInit(); datetime.writeValue('1994-12-15T13:47:20.789Z'); expect(datetime._text).toEqual('1994'); @@ -172,7 +172,7 @@ describe('DateTime', () => { it('should generate with default MMM D, YYYY when no displayFormat or pickerFormat', zoned(() => { datetime.monthShortNames = customLocale.monthShortNames; - datetime.ngAfterContentInit(); + datetime.ngAfterViewInit(); datetime.setValue('1994-12-15T13:47:20.789Z'); datetime.generate(); @@ -186,7 +186,7 @@ describe('DateTime', () => { it('should generate with only displayFormat', zoned(() => { datetime.monthShortNames = customLocale.monthShortNames; - datetime.ngAfterContentInit(); + datetime.ngAfterViewInit(); datetime.displayFormat = 'YYYY'; datetime.setValue('1994-12-15T13:47:20.789Z'); @@ -199,7 +199,7 @@ describe('DateTime', () => { it('should generate with only pickerFormat', zoned(() => { datetime.monthShortNames = customLocale.monthShortNames; - datetime.ngAfterContentInit(); + datetime.ngAfterViewInit(); datetime.pickerFormat = 'YYYY'; datetime.setValue('1994-12-15T13:47:20.789Z'); @@ -212,7 +212,7 @@ describe('DateTime', () => { it('should generate with custom locale short month names from input property', zoned(() => { datetime.monthShortNames = customLocale.monthShortNames; - datetime.ngAfterContentInit(); + datetime.ngAfterViewInit(); datetime.pickerFormat = 'MMM YYYY'; datetime.setValue('1994-12-15T13:47:20.789Z'); @@ -227,7 +227,7 @@ describe('DateTime', () => { it('should generate with custom locale full month names from input property', zoned(() => { datetime.monthNames = customLocale.monthNames; - datetime.ngAfterContentInit(); + datetime.ngAfterViewInit(); datetime.pickerFormat = 'MMMM YYYY'; datetime.setValue('1994-12-15T13:47:20.789Z'); diff --git a/src/components/select/select.ts b/src/components/select/select.ts index 7343540be74..35de7aabb8a 100644 --- a/src/components/select/select.ts +++ b/src/components/select/select.ts @@ -211,11 +211,6 @@ export class Select extends BaseInput implements AfterViewInit, OnDest super(config, elementRef, renderer, 'select', [], form, item, null); } - - ngAfterContentInit() { - this._inputUpdated(); - } - @HostListener('click', ['$event']) _click(ev: UIEvent) { if (ev.detail === 0) { @@ -405,14 +400,14 @@ export class Select extends BaseInput implements AfterViewInit, OnDest set options(val: QueryList