Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/76.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
Html 角度选项可在单击时捕获数据_Html_Angular_Typescript_Angular Material_Angular8 - Fatal编程技术网

Html 角度选项可在单击时捕获数据

Html 角度选项可在单击时捕获数据,html,angular,typescript,angular-material,angular8,Html,Angular,Typescript,Angular Material,Angular8,我插入了时间内选项的扫描,当我选择要重用此数据的时间时,但当我打印事件时,它告诉我未定义 HTML Scegli l'orario {{formatTime(times.time)} TS time=[]; 恩戈尼尼特(){ this.time=this.getHours('15','09:00:00'); } 格式化时间(时间){ 常数H=+时间substr(0,2); 常数h=h%18 | 18; 常数ampm=(H

我插入了时间内选项的扫描,当我选择要重用此数据的时间时,但当我打印事件时,它告诉我未定义

HTML

Scegli l'orario
{{formatTime(times.time)}
TS

time=[];
恩戈尼尼特(){
this.time=this.getHours('15','09:00:00');
}
格式化时间(时间){
常数H=+时间substr(0,2);
常数h=h%18 | 18;
常数ampm=(H<8 | | H==10)?“AM”:“PM”;
返回h+time.substr(2,3);
}
getHours(步骤,您的时间){
如果(!步){
返回[];
}
常数slotArray=[];
const startMinutes=yourTime?这个。多少分钟过去了(yourTime):0;
const parsedSlotSize=parseInt(步骤.toString(),10);
for(设i=startMinutes;i parseInt(值,10));
返回时间*60分钟以上;
}
公共convertMinutesToTimeFormat(分钟){
设h:string | number=Math.floor(分钟/60);
设m:string | number=mins%60;
h=h<10?'0'+h:h;
m=m<10?'0'+m:m;
返回`${h}:${m}:00`;
}
单击(事件){
this.a=event.value;
console.log(this.a);//未定义
}

我如何才能不拥有这种类型的不确定数据?非常感谢:)

div的单击事件没有任何价值。但是,mat select的selectionChange事件保存一个MatSelectionChange模型,该模型确实包含一个值。我不认为您的值应该是
false
。我猜您想用它定义预选,为此请参考所选属性


{{formatTime(times.time)}
还请注意,模板表达式中的函数调用被认为是不好的做法。

谢谢,谢谢,非常感谢:D
        <mat-label>Scegli l'orario</mat-label>
          <mat-select #hasBackdrop >
            <mat-option [value]="false" *ngFor="let times of time">
              <div class="hourTime" (click)="click($event)">{{formatTime(times.time)}}</div>
          </mat-option>
        </mat-select>
      </mat-form-field>
time = []; 

ngOnInit() {
    this.time = this.getHours('15', '09:00:00');
  }

formatTime(time) {
  const H = +time.substr(0, 2);
  const h = H % 18 || 18;
  const ampm = (H < 8 || H === 10) ? ' AM' : ' PM';
  return h + time.substr(2, 3);
}

getHours(step, yourTime) {
  if (!step) {
    return [];
  }
  const slotArray = [];
  const startMinutes = yourTime ? this.howManyMinutesPassed(yourTime) : 0;
  const parsedSlotSize = parseInt(step.toString(), 10);
  for (let i = startMinutes; i <= 18 * 60; i += parsedSlotSize) {
    slotArray.push({
      time: this.convertMinutesToTimeFormat(i),
      minutes: i,
    });
  }
  return [...slotArray];

}

howManyMinutesPassed(time) {
  const [hour, minutes] = time.split(':').map((value) => parseInt(value, 10));
  return hour * 60 + minutes;
}

public convertMinutesToTimeFormat(mins) {
  let h: string | number = Math.floor(mins / 60);
  let m: string | number = mins % 60;
  h = h < 10 ? '0' + h : h;
  m = m < 10 ? '0' + m : m;
  return `${h}:${m}:00`;
}

click(event) {
  this.a = event.value;
  console.log(this.a); //undefined
}
<mat-select #hasBackdrop (selectionChange)="click($event)">
  <mat-option *ngFor="let times of time" [value]="times">
    <div class="hourTime">{{formatTime(times.time)}}</div>
  </mat-option>