Quantcast
Channel: Node.jsタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 8909

はじめてのAngular入門ガイド

$
0
0

Angularプロジェクトの概要と始め方を記載します。Versionの変更がたびたびあるので、内容はリンクは最新のVersionのページを確認すること。

社内教育に使っている資料なのでメモ書きです。

URL

Angular ドキュメント

Angular 基本概念

Angular チュートリアル

アプリケーション生成

ngnewapplication-nameでプロジェクト構成-Routingの設定を聞かれるので>y-cssの設定はscss

起動コマンド

ngserve

http://localhost:4200で画面

ディレクトリ構成

全体感をつかむためにプロジェクトの構造を把握します。ディレクトリ構造を知っておくとバグ時にどのファイルが原因か可能性を絞れるようになります。

コンパイル関係

tsconfig

tsconfig.json:editorから参照されるファイル?(詳細は理解しておらず)tsconfig.base.json:app.json,spec.jsonの両方に継承されているコンパイル設定tsconfig.app.json:通常のコンパイル設定tsconfig.spec.json:テスト用のコンパイル設定

angular.json

Angularプロジェクトのビルドの設定などが記述されている。よく利用して重要なのは以下の3プロパティー。

  • assets: 画像などを格納するdirectory
  • styles: cssやscssなどを格納する。node_modulesに入っているscssなどを入れる。
  • scripts: Javascriptファイルを読み込む
"assets":["src/favicon.ico","src/assets"],"styles":["src/styles.scss"],"scripts":["node_modules/libraryA/js/index.js"]

おそらく最適化などの処理をしてもらえるので、Index.htmlをいじるのでなく上のファイルをいじることでJavaScriptやCSSなどを読み込むのがよい。

その他

とりあえずデフォルトのままで問題ないファイル。

src/test.ssrc/main.tssrc/polyfills.tssrc/index.html

エディター設定ファイル

.editorconfig:エディター一般の構文設定tslint.json:typescriptの構文設定

環境設定ファイル

angular.jsonファイルのコンパイル設定で設定だれている。

envrionments.environment.ts

Angularの構文

特に重要で理解したい概念

  1. Component
  2. Provider(Service)
  3. Module

理解したい構文

以下のdeclarations, imports, providers,exports。bootstrapはとりあえずとばしてよい

@NgModule({declarations:[AppComponent,UserListComponent],imports:[BrowserModule,AppRoutingModule],providers:[],exports:[],bootstrap:[AppComponent]})exportclassAppModule{}

とりあえずすすめたいところ

Getting Started, FundamentalsのComponent Interactionまで

image.png

モジュールとコンポーネント

export, import, declarationとcomponentの関係を正確に理解するのが重要


Yet to be written.

モジュールとコンポーネントの関係を理解するためのデモソースコード
URL: https://github.com/programmerkgit/angular-module-import-demo

Angular Module

  1. Moduleのdeclareに記載されたComponentが利用できるようになる。
  2. componentは同じmodule内でdeclareされた他のcomponentを利用できる。
  3. componentは同じmodule内にimportされたModuleの中でdeclareかつexportされたcomponentを利用できる
  4. MainModuleがChildModuleをimportし、ChildModuleがGrandChildModuleをimportしている場合。ChildModuleがGrandChildModuleをexportすると、MainModuleからGrandChildModuleでexportしているModuleやcomponentにアクセスできる
MainModuledeclaration:[MainComponentA,MainComponentB],import:[ChildModule]ChildModuledeclaration:[ChildComponent,ExportedChildComponent]import:[GrandChildModule,ExportedGrandChildModule],export:[ExportedGrandChildModule]GrandChildModuledeclaration:[GrandChildComponent,ExportedChildComponent]export:[ExportedChildComponent]ExportedGrandChildModuledeclaration:[ExportedGrandChildComponent,ExportedExportedChildComponent]export:[ExportedChildComponent]

Viewing all articles
Browse latest Browse all 8909

Trending Articles