[英]ngb time picker issue with the up and down arrows
I am using bootstrap 4 and ngb time picker for my angular 10 project.我正在为我的 angular 10 项目使用 bootstrap 4 和 ngb 时间选择器。 I added all code correctly.
我正确添加了所有代码。 But time picker up and down arrows not working.
但是时间选择器上下箭头不起作用。 this is my code
这是我的代码
<ngb-timepicker [(ngModel)]="time" formControlName="time"></ngb-timepicker>
my component like below我的组件如下
import { Component, OnInit, ViewChild } from '@angular/core';
import { NgForm } from '@angular/forms';
import { NgbTimeStruct } from '@ng-bootstrap/ng-bootstrap';
@Component({
selector: 'app-my-profile',
templateUrl: './my-profile.component.html',
styleUrls: ['./my-profile.component.css']
})
export class MyProfileComponent implements OnInit {
profile: any = {};
@ViewChild(NgForm) profileform: NgForm;
constructor() { }
ngOnInit() {
}
time: NgbTimeStruct = { hour: 13, minute: 30, second: 0 };
addScheduleCheckin() { }
}
When i click the up and down arrows this error fired.当我单击向上和向下箭头时,会触发此错误。
I can give you a clue.我可以给你一个线索。 I know it's not an answer while I need to past code block, so the comments would not work.
我知道这不是一个答案,而我需要过去的代码块,所以评论不起作用。
The error happens here:错误发生在这里:
changeHour(step: number) {
this.model.changeHour(step);
this.propagateModelChange();
}
For some reason, the model
is undefined
.出于某种原因,
model
是undefined
。 The model
value is set here: model
值在此处设置:
writeValue(value) {
const structValue = this._ngbTimeAdapter.fromModel(value);
this.model = structValue ? new NgbTime(structValue.hour, structValue.minute, structValue.second) : new NgbTime();
if (!this.seconds && (!structValue || !isNumber(structValue.second))) {
this.model.second = 0;
}
this._cd.markForCheck();
}
writeValue
method is part of the ControlValueAccessor
interface. writeValue
方法是ControlValueAccessor
接口的一部分。 It is called when we bind to [ngModel]
.当我们绑定到
[ngModel]
时调用它。 I can not imagine how could it become undefined
if this code block was executed.我无法想象如果执行了这个代码块,它怎么会变得
undefined
。
Let's assume it was not executed.假设它没有被执行。 It could happen either if
FormsModule
was not exported either if there is some error happening before and prevents the writeValue
execution.如果
FormsModule
没有导出,如果之前发生了一些错误并阻止writeValue
执行,则可能会发生这种情况。
I hope this would help you fix the error.我希望这可以帮助您解决错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.