組件我要創建一個表單,我想有關組件角2錯誤:無法找到未指定名稱屬性控制 - 內部部件
更加清晰形式的主要思想是:
FormComponent | > FieldComponent |>表格InputComponent
,所以我有PartnerFormComponent:
HTML:
<form [formGroup]="partnerForm" (ngSubmit)="save()">
<!--<legal-information
[(partner)]="partner" [(partnerConfiguration)]="partnerConfiguration" ></legal-information>-->
<combo-billing-entity [(formGroup)]="partnerForm" [(partner)]="partner" [(partnerConfiguration)]="partnerConfiguration"></combo-billing-entity>
<div class="buttons_form">
<button class="save_button_form" type="submit" [disabled]="!partnerForm.valid">
Add
</button>
<a class="btn-floating btn-large waves-effect waves-light green"
routerLink="/partners">
<i class="material-icons">Cancel</i>
</a>
</div>
</form>
和TS:
@Component({
selector: 'partner-form',
templateUrl: './partner-form.component.html',
styleUrls: ['./partner-form.component.css'],
entryComponents:[LegalInformationComponent]
})
export class PartnerFormComponent implements OnInit {
private partnerForm: FormGroup;
title: string;
partner: Partner = new Partner();
partnerConfiguration: PartnerConfiguration = new PartnerConfiguration();
constructor(
private router: Router,
private route: ActivatedRoute,
private partnerService: PartnerService
) { }
ngOnInit() {
var id = this.route.params.subscribe(params => {
var id = params['id'];
if (!id)
return;
.....
});
}
從組件
然後我有HTML組合:
<div class="components_situation">
<div class="field_form_title">
{{title}} <span class="is_required_form" [hidden]="!isRequired">*</span>
</div>
<div [formGroup]="formGroup" >
<select id="billingEntity" [(ngModel)]="partnerConfiguration.fakeBillingEntity"
formControlName="billingEntity"
[class.invalid]="form.controls['billingEntity'].touched && !form.controls['billingEntity'].valid"
>
<option disabled hidden [value]="selectUndefinedOptionValue">-- select --</option>
<option *ngFor="let obj of billingEntities" [value]="obj.value" >{{obj.name}}</option>
</select>
</div>
<div class="some_explanation_form_field">{{someExplanation}}</div>
</div>
個
和TS:
import {Component, Input, OnInit} from "@angular/core";
import {CommonFieldFormComponent} from "../../common-field-form-component";
import {BillingService} from "../../../../../../services/billing/billing.service";
import {BillingEntitity} from "../../../../../../model/billing_entity";
import {FormBuilder, FormGroup, Validators} from "@angular/forms";
@Component({
selector: 'combo-billing-entity',
templateUrl: './combo-billing-entity.component.html'
})
export class ComboBillingEntityComponent extends CommonFieldFormComponent implements OnInit {
private selectUndefinedOptionValue:any;
billingEntities:BillingEntitity[] = [];
@Input()
private formGroup:FormGroup;
constructor(private billingService: BillingService, private formBuilder:FormBuilder)
{
super();
this.isRequired=true;
this.title="Billing Entity";
this.someExplanation="Identifies entity responsible for billing invoice";
this.formGroup = this.formBuilder.group({
billingEntity :['', Validators.required]
});
}
但畢竟我有這樣的錯誤:
ComboBillingEntityComponent.html:5 ERROR錯誤:無法找到_throwError(forms.es5.js與未指定的name屬性 控制:1852 ) at FormUpControl(forms.es5.js:1760) at FormGroupDirective.webpackJsonp .../../../forms/@angular/forms.es5.js.FormGroupDirective.addControl(forms.es5.js:4733) )在FormControlName上的FormControlName.webpackJsonp處的 .../../../forms/@angular/forms.es5.js.FormControlName._setUpControl(forms.es5.js:5321) olName.webpackJsonp .../../../forms/@angular/forms.es5.js.FormControlName.ngOnChanges(forms.es5.js:5239) at checkAndUpdateDirectiveInline(core.es5.js:10831) at checkAndUpdateNodeInline(core.es5.js:12330) 在checkAndUpdateNode(core.es5.js:12269) 在debugCheckAndUpdateNode(core.es5.js:13130) 在debugCheckDirectivesFn(core.es5.js:13071)
任何想法如何將輸入綁定到主窗體..我在做什麼錯了?
嘿,它是怎麼去的答案?是適合你的,還是你想要進一步的幫助? :) – Alex