Created
August 29, 2020 19:54
-
-
Save nicobytes/437bd5b08637a4c5eb137852694b4ad8 to your computer and use it in GitHub Desktop.
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, OnInit, forwardRef } from '@angular/core'; | |
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'; | |
@Component({ | |
selector: 'app-stepper', | |
templateUrl: './stepper.component.html', | |
styleUrls: ['./stepper.component.scss'], | |
providers: [ | |
{ | |
provide: NG_VALUE_ACCESSOR, | |
useExisting: forwardRef(() => StepperComponent), | |
multi: true | |
} | |
] | |
}) | |
export class StepperComponent implements OnInit, ControlValueAccessor { | |
currentValue = 0; | |
onChange = (_: any) => { }; | |
onTouch = () => { }; | |
isDisabled: boolean; | |
constructor() { } | |
ngOnInit(): void { | |
} | |
add() { | |
this.currentValue = this.currentValue + 1; | |
this.onTouch(); | |
this.onChange(this.currentValue); | |
} | |
sub() { | |
this.currentValue = this.currentValue - 1; | |
this.onTouch(); | |
this.onChange(this.currentValue); | |
} | |
writeValue(value: number): void { | |
if (value) { | |
this.currentValue = value; | |
} | |
} | |
registerOnChange(fn: any): void { | |
this.onChange = fn; | |
} | |
registerOnTouched(fn: any): void { | |
this.onTouch = fn; | |
} | |
setDisabledState(isDisabled: boolean): void { | |
this.isDisabled = isDisabled; | |
} | |
} |
Genial esta informacion
Gracias :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Excelente informacion y muy bien demostrado, gracias!!