按下按钮时出现此错误,这使我可以添加多个电话号码。
InputPhoneComponent.html:37 ERROR TypeError: Cannot convert undefined or null to object
at Function.keys (<anonymous>)
at FormGroup.push../node_modules/@angular/forms/fesm5/forms.js.FormGroup.patchValue (forms.js:3179)
at InputPhoneComponent.push../src/app/components/common/input/phone/input-phone.component.ts.InputPhoneComponent.addPhone (input-phone.component.ts:138)
at Object.eval [as handleEvent] (InputPhoneComponent.html:37)
at handleEvent (core.js:19324)
at callWithDebugContext (core.js:20418)
at Object.debugHandleEvent [as handleEvent] (core.js:20121)
at dispatchEvent (core.js:16773)
at core.js:17220
at HTMLButtonElement.<anonymous> (platform-browser.js:988)
这是按钮html
<input type="tel" id="phone" class="form-control number" style="height: 36px" autocomplete="off"
[formControl]="phone.get('number')"
(ngModelChange)="onPhoneNumberChange(i)"
[placeholder]="selectedCountry.placeHolder" [ngStyle]="getInputStyle()" #focusable>
<div class="input-group-prepend">
<div class="btn-group" role="group" aria-label="Basic example">
<button type="button" class="btn btn-outline-secondary" style="border-radius: 0px;" (click)="deletePhone(i)"
ngbTooltip="Eliminar"
placement="top">
<i class="fa fa-times"></i>
</button>
<button type="button" class="btn btn-outline-secondary" (click)="addPhone()"
*ngIf="formGroup.controls.length == i+1 && phone.valid && phone.value.number"
ngbTooltip="Agregar"
placement="top">
<i class="fa fa-plus"></i>
</button>
在这里遇到组件错误
addPhone() {
Helpers.touchAll(this.formGroup, 'markAsTouched')
if (this.formGroup.valid) {
let form = this.phoneService.getPhoneGroup()
form.patchValue(this.defaultCountry)
this.formGroup.push(form);
}
}