LoginSignup
0
0

More than 5 years have passed since last update.

Angular6 で Angular CLI を使ってコンポーネント、サービス、パイプを自動生成する

Last updated at Posted at 2018-10-11

Angular6 において、 Angular CLI ツールのコマンドで、コンポーネント、サービス、パイプ ファイルを自動で生成するコマンドの備忘録。

コマンド

  • コンポーネント生成
ng generate component sample

実行すると、sample ディレクトリと、その配下に Component, HTML, CSS, Spec(UTソース)ファイルが出来あがる。

  • サービス生成
ng generate service sample

実行すると、Service, Spec(UTソース)ファイルが出来あがる。ディレクトリはできないので、必要あれば事前に作る

  • パイプ生成
ng generate pipe sample

実行すると、Pipe, Spec(UTソース)ファイルが出来あがる。ディレクトリはできないので、必要あれば事前に作る

ちょっとした工夫

私の場合は、コンポーネントとかサービスを app.module.ts の declarations や providers とかに直接ぶら下げるやり方はせず、全て Module を用意して、Module を app.module.ts の imports にぶら下げるやり方の方が直感的に見やすいので、そのようにしてます。

コマンドで生成すると、自動的に declarations や providers に直接ぶら下げるように書き込まれてしまうため、事前にフォルダを切ってから生成し、生成後はインポートに記載をし直す事をおすすめします。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0