我正在开发客户端门户应用程序。 Laravel-5.8是后端,而Angular-7是前端。我正在使用POST REQUEST。
client-quote-landing.component.ts
import { Component, OnInit, Inject, LOCALE_ID, TemplateRef } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import { ClientQuoteService } from '../../../../shared/services/client-quote.service';
import { first } from 'rxjs/operators';
import { ToastrService } from 'ngx-toastr';
import { formatDate } from '@angular/common';
import { Validators, FormBuilder, FormGroup, FormControl } from '@angular/forms';
@Component({
selector: 'app-client-quote-landing',
templateUrl: './client-quote-landing.component.html',
styleUrls: ['./client-quote-landing.component.scss']
})
export class ClientQuoteLandingComponent implements OnInit {
quoteModel: any = {};
formattedAddress = '';
truck_types = [];
constructor(
private clientQuoteService: ClientQuoteService, private toastr: ToastrService,
private router: Router,
@Inject(LOCALE_ID) private locale: string,
private route: ActivatedRoute
) {
this.truck_types = ["Flatbed 20 Ton",
"Flatbed 40 Ton",
"Flatbed 45 Ton",
"Box-body 25 Ton",
"Tautliner 40 Ton",
"Tanker 33,000 Litres",
"Tanker 45,000 Litres",
"Tanker 60,000 Litres",
"LPG Tube",
"CNG Skid"
];
}
ngOnInit() {
window.dispatchEvent(new Event('load'));
window.dispatchEvent(new Event('resize'));
}
client-quote-landing.component.html
<form name="quote" #quoteform="ngForm" (ngSubmit)="onCreateQuote(quoteform);" method="post" novalidate>
<div class="row">
<div class="col-xs-12">
<div class="col-xs-6">
<label for="truck_type">Truck Type<span style="color:red;"> *</span></label>
<select class="form-control select2" style="width: 100%;" [(ngModel)]="quoteModel.truck_type" #truckType="ngModel" name="truck_type" required>
<option [ngValue]="null">Choose a Truck Type</option>
<option [ngValue]="truck_type" *ngFor="let truck_type of truck_types">{{truck_type}}</option>
</select>
<div class="form-feedback" *ngIf="truckType.invalid && ((truckType.dirty || truckType.touched) || quoteform.submitted)">
<div style="color:red;" class="alert alert-danger">Truck Type is required.</div>
</div>
</div>
<div class="col-xs-6">
<label for="loading_date">Loading Date<span style="color:red;"> *</span></label>
<div class="input-group date">
<mat-form-field>
<input matInput [matDatepicker] = "picker" placeholder = "Choose a date" name="loading_date" [(ngModel)]="quoteModel.loading_date" #loading_date="ngModel" [ngClass]="{'is-invalid' : loading_date.invalid && ((loading_date.dirty || loading_date.touched) || quoteform.submitted)}" required>
<mat-datepicker-toggle matSuffix [for] = "picker"></mat-datepicker-toggle>
</mat-form-field>
<div class="form-feedback" *ngIf="loading_date.invalid && ((loading_date.dirty || loading_date.touched) || quoteform.submitted)">
<div style="color:red;" *ngIf="loading_date.errors?.required"class="alert alert-danger">Loading Date is required.</div>
</div>
</div>
</div>
</div>
</div>
<button style="margin:5px" type="submit" class="btn btn-success" > Get A Quote</button>
</form>
当我单击“提交”按钮时,没有任何反应,然后我检查了网络,并收到了以下错误消息:
消息:“ SQLSTATE [HY000]:一般错误:1364字段'truck_type'没有默认值(SQL:插入
client_quotes
(first_name
,last_name
,{ {1}},phone
,business_name
,truck_required
,quote_origin
,quote_destination
,commodity
,{{1 }},loading_date
)值(Michael,Idowu,noblemfd@yahoo.com,23456789022222,jolamic,Flatbed 20 Ton,Abeokuta,Ibadan,rice,2019-09-27T23:00:00.000Z,2019-09- 18 15:31:15,2019-09-18 15:31:15))“
如何解决此错误?
答案 0 :(得分:1)
从错误消息中非常清楚。错误的含义是,在名称 <ng-container>
<div class="table-responsive" >
<table class="table table-condensed table table-bordered table table-striped">
<thead>
<tr>
<th rowspan="2" class="center bold">Number</th>
<th rowspan="2" class="center bold">Name</th>
<th class="center bold">ID</th>
<th class="center bold">Address<br /> (GS03)</th>
</tr>
</thead>
<tbody>
<ng-container *ngFor="let row of BulkRows" >
<tr>
<td class="center">
<span>{{row.addNumber}}</span>
</td>
<td class="center">
<span>{{row.addName}}</span>
</td>
<td class="center">
<span>{{row.addID}}</span>
</td>
<td class="center">
<span>{{row.addAddress}}</span>
</td>
<td class="center">
<span>{{row.addPassword}}</span>
</td>
中有一个名为truck_type
的列,既不允许具有空值,也没有为其定义默认值。在这种情况下,您应该为该列传递一个值,而您并没有这样做。您可以在查询中传递其值,也可以在laravel模式或数据库模式中将其设置为client_quotes
或为其设置默认值。