Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/384.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 带有上下箭头的ngb时间选择器问题_Javascript_Angular_Ng Bootstrap - Fatal编程技术网

Javascript 带有上下箭头的ngb时间选择器问题

Javascript 带有上下箭头的ngb时间选择器问题,javascript,angular,ng-bootstrap,Javascript,Angular,Ng Bootstrap,我正在为我的angular 10项目使用bootstrap 4和ngb时间选择器。我正确地添加了所有代码。但时间选择器上下箭头不起作用。这是我的密码 <ngb-timepicker [(ngModel)]="time" formControlName="time"></ngb-timepicker> 当我单击向上和向下箭头时,会触发此错误 我可以给你一个线索。我知道这不是一个答案,而我需要过去的代码块,所以评论将无法工作 错

我正在为我的angular 10项目使用bootstrap 4和ngb时间选择器。我正确地添加了所有代码。但时间选择器上下箭头不起作用。这是我的密码

  <ngb-timepicker [(ngModel)]="time" formControlName="time"></ngb-timepicker>
当我单击向上和向下箭头时,会触发此错误


我可以给你一个线索。我知道这不是一个答案,而我需要过去的代码块,所以评论将无法工作

错误发生在这里:

changeHour(步骤:编号){
此.model.changeHour(步长);
这个.propagateModelChange();
}
由于某种原因,
模型
未定义的
模型
值在此处设置:

writeValue(值){
const structValue=this.\n ngbTimeAdapter.fromModel(值);
this.model=structValue?新建NgbTime(structValue.hour,structValue.minute,structValue.second):新建NgbTime();
如果(!this.seconds&(!structValue | |!isNumber(structValue.second))){
this.model.second=0;
}
这个._cd.markForCheck();
}
writeValue
方法是
ControlValueAccessor
接口的一部分。当我们绑定到
[ngModel]
时会调用它。我无法想象如果执行此代码块,它怎么会变成
未定义的

让我们假设它没有被执行。如果未导出
FormsModule
,或者之前发生了一些错误并阻止执行
writeValue
,则可能会发生这种情况

我希望这将帮助您修复错误

    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() { }
}