MK
Size: a a a
MK
TP
N
TP
TS
TP
TP
R
this.form = this.fb.group({привет всем! подскажите пж как в notifications который является массивом определить еще 4 поля?
notifications: this.fb.array([])
});
form: FormGroup;
notifications: FormArray = this.fb.array([]);
channels: FormArray = this.fb.array([]);
constructor(public dialogRef: MatDialogRef<NotificationsInSpecificRoleComponent>,
@Inject(MAT_DIALOG_DATA) public availableNotifications: ApiCoreAvailableNotifications[],
private fb: FormBuilder) {
}
ngOnInit(): void {
this.initializeFormArrays();
this.initializeFormBuilder();
}
private initializeFormBuilder(): void {
this.form = this.fb.group({
notifications: this.notifications
});
}
private initializeFormArrays(): void {
this.availableNotifications.forEach(notification => {
let mail = '', webPush = '', gateApi = '', database = '';
notification.channels.forEach(channel => {
switch (channel) {
case WEB_PUSH:
webPush = channel;
break;
case GATE_API:
gateApi = channel;
break;
case DATABASE:
database = channel;
break;
case MAIL:
mail = channel;
break;
}
this.channels.push(new FormControl(channel));
});
this.notifications.push(new FormGroup({
id: new FormControl(notification.id),
title: new FormControl(notification.title),
channel: this.channels
}));
});
}
S
this.form = this.fb.group({привет всем! подскажите пж как в notifications который является массивом определить еще 4 поля?
notifications: this.fb.array([])
});
form: FormGroup;
notifications: FormArray = this.fb.array([]);
channels: FormArray = this.fb.array([]);
constructor(public dialogRef: MatDialogRef<NotificationsInSpecificRoleComponent>,
@Inject(MAT_DIALOG_DATA) public availableNotifications: ApiCoreAvailableNotifications[],
private fb: FormBuilder) {
}
ngOnInit(): void {
this.initializeFormArrays();
this.initializeFormBuilder();
}
private initializeFormBuilder(): void {
this.form = this.fb.group({
notifications: this.notifications
});
}
private initializeFormArrays(): void {
this.availableNotifications.forEach(notification => {
let mail = '', webPush = '', gateApi = '', database = '';
notification.channels.forEach(channel => {
switch (channel) {
case WEB_PUSH:
webPush = channel;
break;
case GATE_API:
gateApi = channel;
break;
case DATABASE:
database = channel;
break;
case MAIL:
mail = channel;
break;
}
this.channels.push(new FormControl(channel));
});
this.notifications.push(new FormGroup({
id: new FormControl(notification.id),
title: new FormControl(notification.title),
channel: this.channels
}));
});
}
R
R
notifications: FormArray = this.fb.array([]);
channels: FormArray = this.fb.array([]);
по отдельности определить и потом пушить один в другой с этим понятно, но как их объявить в одном формбилдере?VM
R
TS
VM
R
R
p
AS
p