Skip to content

Instantly share code, notes, and snippets.

@nicobytes
Created August 29, 2020 19:54
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nicobytes/437bd5b08637a4c5eb137852694b4ad8 to your computer and use it in GitHub Desktop.
Save nicobytes/437bd5b08637a4c5eb137852694b4ad8 to your computer and use it in GitHub Desktop.
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;
}
}
@aAndres441
Copy link

Excelente informacion y muy bien demostrado, gracias!!

@alexperezortuno
Copy link

Genial esta informacion

@leobar37
Copy link

Gracias :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment