mirror of
https://github.com/akveo/ngx-admin.git
synced 2025-12-19 00:40:12 +01:00
feat(inputs\multi-checkbox): add multi-checkbox directive
This commit is contained in:
parent
e63812f011
commit
70cdff101f
12 changed files with 270 additions and 94 deletions
|
|
@ -1,32 +1,36 @@
|
|||
import {Component, Provider, forwardRef, Input} from "@angular/core";
|
||||
import {ControlValueAccessor, NG_VALUE_ACCESSOR} from "@angular/common";
|
||||
|
||||
const BA_CHECKBOX_CONTROL_VALUE_ACCESSOR = new Provider(
|
||||
NG_VALUE_ACCESSOR, {
|
||||
useExisting: forwardRef(() => BaCheckbox),
|
||||
multi: true
|
||||
});
|
||||
import {Component, Input, Self} from '@angular/core';
|
||||
import {ControlValueAccessor, NgModel} from '@angular/forms';
|
||||
|
||||
@Component({
|
||||
selector: 'ba-checkbox',
|
||||
template: require('./baCheckbox.html'),
|
||||
providers: [BA_CHECKBOX_CONTROL_VALUE_ACCESSOR]
|
||||
selector: 'ba-checkbox[ngModel]',
|
||||
styles: [require('./baCheckbox.scss')],
|
||||
template: require('./baCheckbox.html')
|
||||
})
|
||||
export class BaCheckbox implements ControlValueAccessor {
|
||||
@Input() disabled:boolean;
|
||||
@Input() label:string;
|
||||
@Input() value:string;
|
||||
@Input() name:string;
|
||||
@Input() baCheckboxClass:string;
|
||||
|
||||
public model: NgModel;
|
||||
public state: boolean;
|
||||
|
||||
onChange(value: any): void {}
|
||||
onTouch(value: any): void {}
|
||||
writeValue(value: any): void {
|
||||
this.state = value;
|
||||
public constructor(@Self() state:NgModel) {
|
||||
this.model = state;
|
||||
state.valueAccessor = this;
|
||||
}
|
||||
|
||||
registerOnChange(fn: any): void { this.onChange = fn; }
|
||||
registerOnTouched(fn: any): void { this.onTouch = fn; }
|
||||
public onChange(value: any): void {}
|
||||
public onTouch(value: any): void {}
|
||||
public writeValue(state: any): void {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
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; }
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue