Skip to main content

Angular Projectsの4章を読んで不明点をまとめた

Angular Projects

4: Building a PWA Weather Application Using Angular Service Worker
4章を読んで写経して不明点をまとめた


コマンド
・ng add
npm installに加えてスクリプトの実行される

・ファイル生成
ng generate component
ng generate interface
ng generate service

 

レイアウト
・#
テンプレート変数として値が代入される
https://angular.jp/guide/template-reference-variables

・ngIf
レイアウトでngifでチェックすることでnullableをnon-nullにできる
https://zenn.dev/hashito/articles/f0c4c0441b4cd2

 

ロジック
・HttpClientModuleをstandaloneで
provideHttpClientを使えば良い
https://stackoverflow.com/questions/75690545/nullinjectorerror-root-standalone-component-does-not-import-httpclientmodule-p

・http-serverのpath
どこかのバージョンから階層変わった模様
パス一階層掘ったところにする

"server": "http-server -p 8080 -c-1 dist/weather-app/browser”

・コンストラクタの引数
自動的にpropertyになる模様
https://stackoverflow.com/questions/54736178/creating-properties-in-constructor

 

RxJS
・pipe
thenと同じような扱い
https://zenn.dev/mikakane/articles/rxjs_2_tutorial

・pipeに複数の引数を与える
直列で動く
https://zenn.dev/peko858/scraps/f3922eaf19ecd5

 

エラー系
・pipe ‘number’ could not be found
BrowserModule and CommonModuleをimportする
https://stackoverflow.com/questions/54406459/pipe-number-could-not-be-found

・Object is possibly ‘undefined’.ngtsc(2532)
?でnullableのチェックができるみたい
https://stackoverflow.com/questions/54884488/how-can-i-solve-the-error-ts2532-object-is-possibly-undefined

・✘ [ERROR] TS2307: Cannot find module ‘@angular/service-worker’ or its corresponding type declarations. [plugin angular-compiler]
これ理由がよく分からないんだけど、npm installしなおしたら動いた

 

Angular Projects

関連記事:

Pocket