This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
multiCheckControl = new FormControl({ | |
value: TEST_INITIAL_VALUE, | |
disabled: true | |
}); | |
multiCheckControl.disabled(); | |
multiCheckControl.enabled(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class MultiCheckFieldComponent implements ControlValueAccessor { | |
_onChange: (_: any) => void; | |
registerOnChange(fn: any): void { | |
this._onChange = fn; | |
} | |
private add(value: any): void { | |
this.selectedValues.push(value); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component({ | |
selector: 'app-root', | |
template: ` | |
<multi-check-field [formControl]="multiCheckControl"> | |
<simple-check-option *ngFor="let subject of subjects" | |
[value]="subject" [label]="subject.label"> | |
</simple-check-option> | |
</multi-check-field> | |
<button (click)="setTestValue()">Set Test Value</button> | |
Control value: <pre>{{ multiCheckControl.value | json }}</pre> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
writeValue(values: any[]): void { | |
this.selectedValues = []; | |
values = values || []; | |
values.forEach(selectedValue => { | |
const selectedOption = this.options.find(v => v.value === selectedValue); | |
selectedOption.control.setValue(true); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
multiCheckControl = new FormControl(TEST_INITIAL_VALUE); | |
multiCheckControl.setValue(TEST_VALUE); | |
multiCheckControl.patchValue(TEST_VALUE); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
writeValue(obj: any): void; | |
registerOnChange(fn: any): void; | |
registerOnTouched(fn: any): void; | |
setDisabledState?(isDisabled: boolean): void; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, forwardRef } from '@angular/core'; | |
import { NG_VALUE_ACCESSOR } from '@angular/forms'; | |
@Component({ | |
selector: 'multi-check-field', | |
providers: [ | |
{ | |
provide: NG_VALUE_ACCESSOR, | |
useExisting: forwardRef(() => MultiCheckFieldComponent), | |
multi: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<multi-check-field formControlName="subjects"> | |
... | |
</multi-check-field> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export abstract class MultiCheckOption { | |
abstract value: any; | |
public control = new FormControl(false); | |
get valueChanges$(): Observable<boolean> { | |
return this.control.valueChanges; | |
} | |
} | |
@Component(...) | |
export class SimpleCheckOptionComponent extends MultiCheckOption { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ContentChildren(MultiCheckOption) | |
options!: QueryList<MultiCheckOption>; |
NewerOlder