【发布时间】:2019-10-26 21:01:27
【问题描述】:
我不知道是否有办法将 .ts 文件中的变量值绑定到输入值、最小值和最大值属性。 我尝试了很多方法,但似乎没有一个有效。
我有两种方式从输入字段 [(ngModel)]="transferPoint.arrivalTime 获取值,但我需要将 min 和 max 属性设置为某些值。
这不起作用:min='{{flight.departureTime}}'
这是我的 html 文件
<h1 mat-dialog-title>ADD NEW TRANSFER POINT</h1>
<div mat-dialog-content>
<mat-form-field>
<input type="datetime-local" id="arrival-time" name="arrival-time" value="{{flight.departureTime}}" min="{{flight.departureTime}}"
max="{{flight.arrivalTime}}" matInput [(ngModel)]="transferPoint.arrivalTime" placeholder="Arrival time">
</mat-form-field>
<br>
<mat-form-field>
<input type="datetime-local" id="departure-time" name="departure-time" value="2018-06-12T19:30" min="2018-06-07T00:00"
max="2018-06-14T00:00" matInput [(ngModel)]="transferPoint.departureTime" placeholder="Departure time">
</mat-form-field>
<br>
<mat-form-field>
<input matInput [(ngModel)]="transferPoint.countryAndCity" placeholder="Country and City">
</mat-form-field>
</div>
<div mat-dialog-actions>
<button class="submitbtn" mat-raised-button (click)='addTransferPoint()'>ADD</button>
<button class="cancelbtn" mat-raised-button mat-dialog-close>CANCEL</button>
</div>
这是我的 .ts 文件
export class AddTransferPointComponent implements OnInit {
errorMessage: string;
flightId: any;
flight: FlightDTO;
transferPoint: TransferPointDTO = new TransferPointDTO();
constructor(@Inject(MAT_DIALOG_DATA) public data: any,
public dialogRef: MatDialogRef<any>,
private transferPointService: TransferService,
private flightService: FlightService) { }
ngOnInit() {
this.flightId = this.data.flight;
}
getFlight() {
this.flightService.getFlight(this.flightId).subscribe(
data => {
this.flight = data;
}
)
}
addTransferPoint() {
this.transferPoint.flightId = this.flightId;
this.transferPointService.createTransferPoint(this.transferPoint).subscribe(
data => {
this.dialogRef.close();
location.reload();
},
error => {
console.log(error);
this.errorMessage = error.error.message;
}
);
}
}
【问题讨论】:
标签: html angular data-binding