前提
angularのプロジェクトで以下のようなファイル構成になっていることがあります。
- aaa.component.ts
- aaa.service.ts
- b-aaa.component.ts
- b-aaa.service.ts
- aaa.component.html
- aaa.component.css
各ファイルの中身を見るとなんとなくそれぞれの役割は分かるのですが、いまいち人に説明できるレベルまで理解しきれていません。
- serviceとcomponentの役割の違いはなにか?
- なぜ
b-
をプレフィックスしたファイルが必要なのか?またb-
とはどういう意味なのか?(バインディング?)
をご存知であれば教えて頂けると幸いです。
よろしくお願いたします。
追加情報
Angular CLI: 11.2.4
Node: 14.15.4
Angular: 11.2.5
またそれぞれのファイルには以下のような内容の記述です。(import部分は省略し多少簡略化しています。)
aaa.component.ts
ts
1@Component({ 2 selector: 'app-aaa', 3 templateUrl: './aaa.component.html', 4 styleUrls: ['./aaa.component.css'], 5 providers: [AaaService], 6 changeDetection: ChangeDetectionStrategy.OnPush, 7}) 8export class aaaComponent extends BaaaComponent { 9 constructor( 10 aaaService: AaaService, 11 ) { 12 super(aaaService); 13 } 14}
aaa.service.ts
ts
1@Injectable() 2export class aaaService extends BaaaService { 3 constructor( 4 datePipe: DatePipe, 5 ) { 6 super(datePipe); 7 } 8}
b-aaa.component.ts
ts
1@Component({ 2 template: '', 3 changeDetection: ChangeDetectionStrategy.OnPush, 4}) 5export abstract class BaaaComponent implements OnInit, AfterViewInit, OnDestroy, DoCheck { 6 7 ngOnInit(): void { 8 this.aaaService.initAaa(): 9 ...(省略) 10 } 11 12 ngDoCheck() { 13 ...(省略) 14 } 15 16 ngAfterViewInit(): void { 17 ...(省略) 18 } 19 20 ngOnDestroy() { 21 ...(省略) 22 } 23}
b-aaa.service.ts
ts
1@Injectable() 2export class foo { 3 4 async initAaa() ( 5 ...(省略) 6 } 7 8 addData() { 9 ...(省略) 10 } 11 12}
回答1件
あなたの回答
tips
プレビュー