From 47d1111b6b0559e79dce956193c2598c8a8de0d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=AA=20Anh=20=C4=90=E1=BB=A9c?= Date: Fri, 10 Jun 2022 16:13:32 +0700 Subject: [PATCH] =?UTF-8?q?Th=C3=AAm=20ControlValueAccessor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'; --- .../bravo-slider/bravo-slider.component.ts | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/angular/src/app/bravo-slider/bravo-slider.component.ts b/angular/src/app/bravo-slider/bravo-slider.component.ts index b7c6487..b3185dc 100644 --- a/angular/src/app/bravo-slider/bravo-slider.component.ts +++ b/angular/src/app/bravo-slider/bravo-slider.component.ts @@ -7,18 +7,31 @@ import { Component, ElementRef, EventEmitter, + forwardRef, Input, OnInit, Output, } from '@angular/core'; import * as wjc from '@grapecity/wijmo'; +import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'; + @Component({ selector: 'bravo-slider', templateUrl: './bravo-slider.component.html', styleUrls: ['./bravo-slider.component.css'], + providers: [ + { + provide: NG_VALUE_ACCESSOR, + multi: true, + useExisting: forwardRef(() => BravoSliderComponent), + }, + ], }) -export class BravoSliderComponent extends wjc.Control implements OnInit { +export class BravoSliderComponent + extends wjc.Control + implements OnInit, ControlValueAccessor +{ @Input() public start!: number; @@ -191,6 +204,19 @@ export class BravoSliderComponent extends wjc.Control implements OnInit { super(elementRef.nativeElement); } + private onTouchedCallback = (value: any) => {}; + private onChangeCallback = (value: any) => {}; + + writeValue(obj: any): void {} + + public registerOnChange(onChangeCallback: any): void { + this.onChangeCallback = onChangeCallback; + } + + public registerOnTouched(onTouchedCallback: any): void { + this.onTouchedCallback = onTouchedCallback; + } + override refresh(fullUpdate?: boolean): void { this.bubble(this.isBubble); this.pointer(