Skip to content

Instantly share code, notes, and snippets.

@Stradivario
Last active March 14, 2022 17:08
Show Gist options
  • Save Stradivario/f798947d82996fd5f68987693f531b63 to your computer and use it in GitHub Desktop.
Save Stradivario/f798947d82996fd5f68987693f531b63 to your computer and use it in GitHub Desktop.
import {Component, EventEmitter, Input, Output} from '@angular/core';
import {ControlValueAccessor, VALUE_ACCESSOR} from '';
@Component({
selector: 'catalog-counter',
templateUrl: './counter.component.html',
styleUrls: ['./counter.component.scss'],
providers: [VALUE_ACCESSOR(CounterComponent)],
})
export class CounterComponent extends ControlValueAccessor {
@Output()
valueChange = new EventEmitter<number>();
@Input()
value = 0;
changeValue(value: number) {
if (this.isZeroOrBigger(value)) {
this.value = this.value + value;
this.valueChange.next(this.value);
this.pushChanges(this.value);
}
}
private isZeroOrBigger(value: number) {
return this.value + value > -1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment