This file contains hidden or 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
| private subscriptions = new Subscription(); | |
| private selectedValues: any[] = []; | |
| ngAfterContentInit(): void { | |
| this.options.forEach(option => { | |
| this.subscriptions.add( | |
| option.valueChanges$.subscribe( | |
| (optionChecked) => { | |
| if (optionChecked) { | |
| this.add(option.value); |
This file contains hidden or 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: 'user-check-option', | |
| template: ` | |
| <label> | |
| <input type="checkbox" [formControl]="control"> | |
| <div class="card"> | |
| <div class="avatar"> | |
| <img src="assets/images/{{ value.avatar }}"> | |
| <div class="span"></div> | |
| </div> |
This file contains hidden or 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(SimpleCheckOptionComponent) | |
| options!: QueryList<SimpleCheckOptionComponent>; |
This file contains hidden or 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
| abstract class MultiCheckOption { } // (1) | |
| @Component({ | |
| selector: 'simple-check-option', | |
| providers: [ | |
| { // (2) | |
| provide: MultiCheckOption, | |
| useExisting: SimpleCheckOptionComponent, | |
| } | |
| ] |
This file contains hidden or 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>; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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); |