mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-17 02:31:34 +08:00

committed by
Manu MA

parent
359bdcf8ec
commit
b645bfd1b7
@ -1,7 +1,7 @@
|
|||||||
import { Directive, ElementRef, HostListener } from '@angular/core';
|
import { Directive, ElementRef, HostListener } from '@angular/core';
|
||||||
import { NG_VALUE_ACCESSOR } from '@angular/forms';
|
import { NG_VALUE_ACCESSOR } from '@angular/forms';
|
||||||
|
|
||||||
import { ValueAccessor } from './value-accessor';
|
import { ValueAccessor, setIonicClasses } from './value-accessor';
|
||||||
|
|
||||||
@Directive({
|
@Directive({
|
||||||
/* tslint:disable-next-line:directive-selector */
|
/* tslint:disable-next-line:directive-selector */
|
||||||
@ -20,6 +20,11 @@ export class BooleanValueAccessor extends ValueAccessor {
|
|||||||
super(el);
|
super(el);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
writeValue(value: any) {
|
||||||
|
this.el.nativeElement.checked = this.lastValue = value == null ? '' : value;
|
||||||
|
setIonicClasses(this.el);
|
||||||
|
}
|
||||||
|
|
||||||
@HostListener('ionChange', ['$event.target.checked'])
|
@HostListener('ionChange', ['$event.target.checked'])
|
||||||
_handleIonChange(value: any) {
|
_handleIonChange(value: any) {
|
||||||
this.handleChangeEvent(value);
|
this.handleChangeEvent(value);
|
||||||
|
@ -5,9 +5,9 @@ export class ValueAccessor implements ControlValueAccessor {
|
|||||||
|
|
||||||
private onChange: (value: any) => void = () => {/**/};
|
private onChange: (value: any) => void = () => {/**/};
|
||||||
private onTouched: () => void = () => {/**/};
|
private onTouched: () => void = () => {/**/};
|
||||||
private lastValue: any;
|
protected lastValue: any;
|
||||||
|
|
||||||
constructor(private el: ElementRef) {}
|
constructor(protected el: ElementRef) {}
|
||||||
|
|
||||||
writeValue(value: any) {
|
writeValue(value: any) {
|
||||||
this.el.nativeElement.value = this.lastValue = value == null ? '' : value;
|
this.el.nativeElement.value = this.lastValue = value == null ? '' : value;
|
||||||
@ -41,7 +41,7 @@ export class ValueAccessor implements ControlValueAccessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function setIonicClasses(element: ElementRef) {
|
export function setIonicClasses(element: ElementRef) {
|
||||||
requestAnimationFrame(() => {
|
requestAnimationFrame(() => {
|
||||||
const classList = (element.nativeElement as HTMLElement).classList;
|
const classList = (element.nativeElement as HTMLElement).classList;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user