How to loop through a range of numbers for example: 0 to 10, in prime ng input number spinner?
Asked
Active
Viewed 346 times
1 Answers
0
<p-inputNumber [showButtons]="true" formControlName="timeHour" [step]='1' [size]='2' value="12">
</p-inputNumber>
export class AppComponent implements OnInit, OnDestroy {
destroy$: Subject<boolean> = new Subject<boolean>();
myForm = new FormGroup({
timeHour: new FormControl(12)
});
constructor() {}
ngOnInit() {
this.spinnerChange();
}
spinnerChange(): void{
this.myForm.get('timeHour').valueChanges
.pipe(
distinctUntilChanged(),
takeUntil(this.destroy$)
)
.subscribe(x => {
const valueChangedHour = x < 1 ? 12 :
(x > 12 ? 1 : x);
this.myForm.patchValue({
timeHour : valueChangedHour
});
});
}
ngOnDestroy() {
this.destroy$.next(true);
// Now let's also unsubscribe from the subject itself:
this.destroy$.unsubscribe();
}
}

Kusuma S V
- 1
- 1