fix(forms): normalize written value in NumberValueAccessor

Closes #10379
This commit is contained in:
Marc Laval 2016-07-29 15:53:22 +02:00
parent 763ca60f5b
commit b48f7bcb8d
2 changed files with 8 additions and 4 deletions

View File

@ -8,7 +8,7 @@
import {Directive, ElementRef, Renderer, forwardRef} from '@angular/core';
import {NumberWrapper} from '../../facade/lang';
import {NumberWrapper, isBlank} from '../../facade/lang';
import {ControlValueAccessor, NG_VALUE_ACCESSOR} from './control_value_accessor';
@ -44,7 +44,9 @@ export class NumberValueAccessor implements ControlValueAccessor {
constructor(private _renderer: Renderer, private _elementRef: ElementRef) {}
writeValue(value: number): void {
this._renderer.setElementProperty(this._elementRef.nativeElement, 'value', value);
// The value needs to be normalized for IE9, otherwise it is set to 'null' when null
const normalizedValue = isBlank(value) ? '' : value;
this._renderer.setElementProperty(this._elementRef.nativeElement, 'value', normalizedValue);
}
registerOnChange(fn: (_: number) => void): void {

View File

@ -8,7 +8,7 @@
import {Directive, ElementRef, Renderer, forwardRef} from '@angular/core';
import {NumberWrapper} from '../facade/lang';
import {NumberWrapper, isBlank} from '../facade/lang';
import {ControlValueAccessor, NG_VALUE_ACCESSOR} from './control_value_accessor';
@ -44,7 +44,9 @@ export class NumberValueAccessor implements ControlValueAccessor {
constructor(private _renderer: Renderer, private _elementRef: ElementRef) {}
writeValue(value: number): void {
this._renderer.setElementProperty(this._elementRef.nativeElement, 'value', value);
// The value needs to be normalized for IE9, otherwise it is set to 'null' when null
const normalizedValue = isBlank(value) ? '' : value;
this._renderer.setElementProperty(this._elementRef.nativeElement, 'value', normalizedValue);
}
registerOnChange(fn: (_: number) => void): void {