Last active
March 14, 2022 17:08
-
-
Save Stradivario/f798947d82996fd5f68987693f531b63 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, 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