Reputation: 163
In Angular 7, I'm creating a component that has many radio button groups. The values of each of these groups are coming from a database. Should I create 1 service to fetch all the values (although they are all independent of each other and have different structures) or should I create a service for each radio button group?
import { Component, OnInit, Input } from '@angular/core';
@Component({
selector: 'app-settings',
template: '
<mat-radio-group [(ngModel)]="dropdown1">
<mat-radio-button *ngFor="let c of dd1" [value]="c.id">
{{c.description}}
</mat-radio-button>
</mat-radio-group>
<mat-radio-group [(ngModel)]="dropdown2">
<mat-radio-button *ngFor="let c of dd2" [value]="c.id">
{{c.description}}
</mat-radio-button>
</mat-radio-group>
[...]
',
styleUrls: ['./settings.component.css']
})
export class FtpSettingsComponent implements OnInit {
@Input() dropdown1: string;
@Input() dropdown2: string;
@Input() dropdown3: string;
dd1: Array<{id: number, description: string}> = [...];
dd2: Array<{id: number, description: string}> = [...];
[...]
}
Upvotes: 0
Views: 88
Reputation: 716
Actually it really depends on the structure and url that you use to get data for that radio buttons! If they come from different urls and different datas should be parsed you better write separate services for each of them. Else if they are use same url api its better to include them in one service component
Upvotes: 1