Angular 在质数ng中的特定数字范围内循环-输入数字微调器
如何循环一系列数字,例如:0到10,在素数ng输入数字微调器中?Angular 在质数ng中的特定数字范围内循环-输入数字微调器,angular,primeng,rxjs-observables,Angular,Primeng,Rxjs Observables,如何循环一系列数字,例如:0到10,在素数ng输入数字微调器中? <p-inputNumber [showButtons]="true" formControlName="timeHour" [step]='1' [size]='2' value="12"> </p-inputNumber> export class AppComponent implements OnInit, OnDestroy {
<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();
}
}
导出类AppComponent实现OnInit、OnDestroy{
销毁$:主题=新主题();
myForm=新FormGroup({
时间小时:新窗体控件(12)
});
构造函数(){}
恩戈尼尼特(){
这个。喷丝头改变();
}
喷丝头更改():无效{
this.myForm.get('timeHour').valueChanges
.烟斗(
distinctUntilChanged(),
takeUntil(此.destroy$)
)
.订阅(x=>{
常数值变化小时=x<1?12:
(x>12?1:x);
this.myForm.patchValue({
timeHour:valueChangedHour
});
});
}
恩贡德斯特罗(){
this.destroy$next(true);
//现在让我们也退订主题本身:
此.destroy$.unsubscribe();
}
}