2016-07-08 17:00:07 +03:00
|
|
|
import {Component, Input, Self} from '@angular/core';
|
|
|
|
|
import {ControlValueAccessor, NgModel} from '@angular/forms';
|
2016-07-07 15:25:08 +03:00
|
|
|
|
|
|
|
|
@Component({
|
2016-07-08 17:00:07 +03:00
|
|
|
selector: 'ba-checkbox[ngModel]',
|
|
|
|
|
styles: [require('./baCheckbox.scss')],
|
|
|
|
|
template: require('./baCheckbox.html')
|
2016-07-07 15:25:08 +03:00
|
|
|
})
|
|
|
|
|
export class BaCheckbox implements ControlValueAccessor {
|
|
|
|
|
@Input() disabled:boolean;
|
|
|
|
|
@Input() label:string;
|
|
|
|
|
@Input() value:string;
|
|
|
|
|
@Input() baCheckboxClass:string;
|
|
|
|
|
|
2016-07-08 17:00:07 +03:00
|
|
|
public model: NgModel;
|
2016-07-07 15:25:08 +03:00
|
|
|
public state: boolean;
|
|
|
|
|
|
2016-07-08 17:00:07 +03:00
|
|
|
public constructor(@Self() state:NgModel) {
|
|
|
|
|
this.model = state;
|
|
|
|
|
state.valueAccessor = this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public onChange(value: any): void {}
|
|
|
|
|
public onTouch(value: any): void {}
|
|
|
|
|
public writeValue(state: any): void {
|
|
|
|
|
this.state = state;
|
2016-07-07 15:25:08 +03:00
|
|
|
}
|
|
|
|
|
|
2016-07-08 17:00:07 +03:00
|
|
|
public registerOnChange(fn: any): void {
|
|
|
|
|
this.onChange = function(state: boolean) {
|
|
|
|
|
this.writeValue(state);
|
|
|
|
|
this.model.viewToModelUpdate(state);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public registerOnTouched(fn: any): void { this.onTouch = fn; }
|
2016-07-07 15:25:08 +03:00
|
|
|
}
|