我收到此错误:
尚未向此数组注册任何表单控件。如果您使用的是 ngModel,您可能需要检查下一个刻度(例如使用 setTimeout)。
使用此代码时:
public settingsForm: FormGroup = this.fb.group({
collaborators: this.fb.array([]),
rsvp: this.fb.group({
latestDate: ['', [Validators.required]],
latestTime: ['', [Validators.required]],
guestLimit: ['', [Validators.required]],
isRSVPOpen: false,
isGuestPlusOne: false,
isAutoApproveToGuestlist: false,
isOnlyFacebookRSVP: false,
isBirthdayAndPhoneRequired: false
}),
tickets: this.fb.group({
info: this.fb.group({
closingDate: '',
closingTime: ''
}),
types: this.fb.array([])
})
});
内部ngOnInit
:
this.eventSubscription = this.af.database.object('/events/' + this.eventId)
.filter(event => event['$value'] !== null)
.subscribe((event: IEvent) => {
const settings: ISettings = event.settings;
const collaborators: ICollaborator[] = settings.collaborators;
const rsvp: IRSVP = settings.rsvp;
const tickets: ITickets = settings.tickets;
this.settingsForm.setValue({
collaborators: collaborators || [],
rsvp: rsvp,
tickets: {
info: tickets.info,
types: tickets.types || []
}
});
}
);
当collaborators
包含一个值,即它不是undefined
,null
或为空[]
,类似于:
[
{
email: 'foo@bar.com',
role: 1
},
{
email: 'baz@bar.com',
role: 2
}
]
然后应用程序setValue
在eventSubscription
.
我无法弄清楚为什么会这样。
有任何想法吗?