我在Angular 5项目中使用了ng2-eonasdan-datetimepicker,但是当我仅使用它选择年份时,我的值出现了问题。
我选择了年份,并且该值正确显示在输入中,但是当我显示来自formBuilder.get的值时,还会显示其他值:
我只需要一年就可以发送到我的API。该如何解决?
我的输入
<div class="form-group" [ngClass]="{'has-error' : hasError('modelYear', 'vehicle')}">
<label>Ano {{ createRemovalForm.get('vehicle.modelYear').value }}</label>
<input type="text" a2e-datetimepicker [options]="{locale: 'pt-br', format: 'YYYY'}" class="form-control dt-placeholder" placeholder="Ano" formControlName="modelYear">
</div>
FormBuilder:
this.createRemovalForm = this.fb.group({
idAuction: ['', Validators.required],
idRemovalType: ['', Validators.required],
addressRemLat: ['', Validators.required],
addressRemLng: ['', Validators.required],
addressRemShort: ['', Validators.required],
addressRemLong: ['', Validators.required],
addressRemCity: ['', Validators.required],
financedInsuredName: ['', Validators.required],
bankInsurerName: ['', Validators.required],
contract: ['', Validators.required],
acessory: ['', Validators.required],
scheduled: [true, Validators.required],
dtToRemove: ['', Validators.required],
contactName: ['', Validators.required],
contactPhone: ['', Validators.required],
vehicle: this.fb.group({
idRequestVehicleType: ['', Validators.required],
manufacturer: ['', Validators.required],
model: ['', Validators.required],
color: ['', Validators.required],
modelYear: ['', Validators.required],
plate: ['', Validators.required],
chassis: ['', Validators.required],
observation: [],
})
});
答案 0 :(得分:0)
您可以使用-
这样的传递选项进行检查吗选项= { 格式:“ YYYY”, };
在这里检查-https://www.npmjs.com/package/ng2-eonasdan-datetimepicker