我对Angular 4很新,我想将变量的值从“小时”更改为“天”,并将ngModel给出的值除以8。我该怎么做?Angular 4 - 如何让我的复选框更改变量的值?
下面是从我summary.component.html的摘录:
<div class="onoffswitch">
<input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch" checked>
<label class="onoffswitch-label" for="myonoffswitch">
<span class="onoffswitch-inner"></span>
<span class="onoffswitch-switch"></span>
</label>
</div>
<div class="panel-body">
<form class="form-horizontal" role="form" style="overflow-x:auto;">
<fieldset>
<div class="col-xs-6">
<div class="form-group" *ngIf="empInfo && empInfo.length > selectedIndex">
<label class="col-xs-2" style="font-weight: bold;"> + </label>
<label class="col-xs-4"> Carryover </label>
<div class="col-xs-6">
<input class='form-control' type="text" id="ptoCarry" [(ngModel)]="empInfo[selectedIndex].PTOCarry + timeVar" name="ptoCarry"/>
</div>
</div>
</div>
</fieldset>
</form>
</div>
,然后这里是我的summary.component.ts:
import { Component, OnInit } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { EmpInfoService } from './emp-info.service';
import { EmpInfo } from './emp-info';
@Component({
selector: 'pto-summary',
templateUrl: `./summary.component.html`,
styleUrls: ['./summary.component.css']
})
export class SummaryComponent implements OnInit{
empInfo: EmpInfo[];
selectedIndex = 4;
timeVar = " hours";
constructor(private empInfoService: EmpInfoService) { }
getEmpInfo(): void {
this.empInfoService.getEmpInfos().then(
empInfo => this.empInfo = empInfo
);
}
ngOnInit(): void {
this.getEmpInfo();
}
}
这里是我的empInfo对象:
export class EmpInfo {
EmpKey: number;
EmpID: string;
Firstname: string;
LastName: string;
EmpStat: string;
StartDate: Date;
AdjustedStart: Date;
Anniversary: number;
PTOYear: number;
STDLTD: number;
Uncharged: number;
ETOEarned: number;
ETORequests: number;
ETORemaining: number;
PTOBase: number;
PTOCarry: number;
PTOBorrowed: number;
PTOBalance: number;
PTORequests: number;
PTORemaining: number;
}
任何帮助是极大的赞赏和欢迎!提前致谢!
ngModel应该有'empInfo [selectedIndex] [PTOCarry + timeVar]',你能分享你'empInfo'对象吗? –
我会如何将它重写为2D数组?并更新原始文章。 – asdf