I don't know if there is a way to bind variable values from .ts file to input value, min and max properties. I've tried many ways, but none seems to be working.
I have two-way biding to get the value from input field [(ngModel)]="transferPoint.arrivalTime, but I need to set min and max properties to certain values.
This is not working: min='{{flight.departureTime}}'
This is my html file
<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>
and here is my .ts file
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;
}
);
}
}
You can use property binding (see also https://angular.io/guide/template-syntax):
<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">