Skip to main content

Angular Projectsの2章のBasic Layoutを読んだ

Angular Projects

2. Building an SPA Application with Scully and Angular Router
このBasci Layoutを読んだの感想


・angurlarのバージョンを確認方法
ng version

 

・app.module.ts
angular17でなくなった
だからこの本あんまり役に立たない
https://stackoverflow.com/questions/77454741/why-doesnt-app-module-exist-in-angular-17

 

・ngコマンド(module)
ng generate module app-routing –flat –module=app
https://angular.jp/tutorial/tour-of-heroes/toh-pt5

・ngコマンド(component)
mng generate component header –path=src/app/core –module=core –export
exportは他から利用できる

 

・NGModule
standaloneだとdeclarationsでなくimportにいれる
https://qiita.com/kakkie/items/d6925de7d233a45ac727

 

・エラー1
Component HeaderComponent is standalone, and cannot be declared in an NgModule. Did you mean to import it instead
の解決策
https://stackoverflow.com/questions/72517141/how-to-import-standalone-components-from-a-lib-in-angular-14
app.component.tsに以下を追加

imports: [RouterOutlet, CoreModule, SharedModule],

・エラー2
[ERROR] TS-996004: Can’t be exported from this NgModule, as it must be imported first [plugin angular-compiler]
の解決策

@NgModule({
  declarations: [],
  imports: [
    CommonModule,
    FooterComponent
  ],
  exports: [
    FooterComponent
  ]
})

・エラー3
NG8004: No pipe found with name ‘date’
の解決策

@Component({
  selector: 'app-footer',
  standalone: true,
  imports: [CommonModule],
  templateUrl: './footer.component.html',
  styleUrl: './footer.component.scss'
})

Angular Projects

関連記事:

Pocket