Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Angularのコンポーネントを知る
Search
ponday
May 29, 2017
Programming
0
130
Angularのコンポーネントを知る
Angular触ろうの会 in Fukuoka #2(2017/05/29)の発表資料です。
ponday
May 29, 2017
Tweet
Share
More Decks by ponday
See All by ponday
関数型でGoFのデザインパターンやってみる
honda
1
1.6k
TypeScriptの型表現
honda
10
3.1k
Web Componentsの今
honda
1
460
これまでのReact、これからのReact
honda
0
320
Gatsbyお試し
honda
0
130
styled-components or emotion?
honda
0
710
Web ComponentsとAngular
honda
0
140
Atomic Design周りについての私見
honda
1
770
え、まだWeb Componentsを未来の技術だと思ってるの?
honda
2
870
Other Decks in Programming
See All in Programming
Unicodeどうしてる? PHPから見たUnicode対応と他言語での対応についてのお伺い
youkidearitai
PRO
1
2.5k
2026年 エンジニアリング自己学習法
yumechi
0
130
CSC307 Lecture 06
javiergs
PRO
0
680
AI によるインシデント初動調査の自動化を行う AI インシデントコマンダーを作った話
azukiazusa1
1
720
HTTPプロトコル正しく理解していますか? 〜かわいい猫と共に学ぼう。ฅ^•ω•^ฅ ニャ〜
hekuchan
2
690
Honoを使ったリモートMCPサーバでAIツールとの連携を加速させる!
tosuri13
1
180
dchart: charts from deck markup
ajstarks
3
990
KIKI_MBSD Cybersecurity Challenges 2025
ikema
0
1.3k
CSC307 Lecture 08
javiergs
PRO
0
670
AIエージェントのキホンから学ぶ「エージェンティックコーディング」実践入門
masahiro_nishimi
5
440
15年続くIoTサービスのSREエンジニアが挑む分散トレーシング導入
melonps
2
200
責任感のあるCloudWatchアラームを設計しよう
akihisaikeda
3
170
Featured
See All Featured
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Producing Creativity
orderedlist
PRO
348
40k
Darren the Foodie - Storyboard
khoart
PRO
2
2.4k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
74
How to Think Like a Performance Engineer
csswizardry
28
2.4k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
180
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.8k
Building an army of robots
kneath
306
46k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.6k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
240
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.1k
It's Worth the Effort
3n
188
29k
Transcript
AngularのComponentを知る Angularを触ろうの会 in Fukuoka #2 / May 29, 2017 ponday(@ponday_dev)
Profile ponday / 本田 裕介 (Honda, Yusuke) name - chibi-developer
- ng-fukuoka スタッフ community - Kotlin, Java, C# etc... - JavaScript - Angular, Vue.js skill
本日のテーマ
@Component
@Component - AngularのComponentを定義するときに付けるDecorator - @angular/coreに定義されている - Angular CLIでは『ng g component
<コンポーネント名>』で生成可能 - Directiveの一種 - DOMのテンプレートを持つComponent - DOMのテンプレートを持たないAttribute Directive - DOMの表示を制御するStructural Directive
@Component 実はこのComponent、結構オプションが多いんです
@Componentのオプション
selector
selector - ComponentのDOM上でのセレクタを定義する。 - ここで定義したセレクタをテンプレート上に記述することでコンポーネントが使用でき る。 - 本当にセレクタなのでタグ名以外でも指定可能。 - 例
- selector: ‘#component’ - selector: ‘.component’ - selector: ‘[component]’ etc…
selector 通常、コンポーネントのレンダリング後もレンダリング先のタグが残る。 残ってる
selector IDやクラス、属性を指定することでHTMLタグのみでレンダリング可 HTMLのタグのみ
encapsulation
encapsulation - CSSによるスタイリングのカプセル化の挙動を指定できる。 - 指定できるのは以下の3種類 - ViewEncapsulation.Emulated - デフォルト値 -
各要素に自動的に属性を割り当ててカプセル化を実現 - ViewEncupsulation.Native - Shadow DOMを使ってカプセル化を実現 - ブラウザのShadow DOM対応が必須。現状ChromeかOperaでしか動かない - ViewEncapsulation.None - カプセル化をせず、グローバルスコープに展開する。 - スタイルが一切指定されていない場合、自動的にNoneになるらしい
changeDetection
changeDetection:前提知識 - Change Detection = 変更検知 - Chenge Detectionを行う仕組み =
Change Detector - コンポーネントごとに保持 - DOMツリー同様に、Change Detectorのツリーが構成されている。 - 各プロパティ(@Inputなど)の値の変更をViewに反映 - zone.jsにより、DOMイベントやAjax通信などあらゆる非同期イベントの発生をフック。値の 変更をチェックする。 - 通常状態ではイベントが発生するたびにすべてのコンポーネントの値の変更を チェックしている。
changeDetection:前提知識 常にすべてのコンポーネントの値の変更をチェック → ムダが多い
changeDetection - Change Detectorの変更検知のタイミングを制御 - 指定できるのは以下の2種類 - ChangeDetectionStrategy.Default - デフォルト値
- このコンポーネントおよび配下について常に値の変更をチェック - ChangeDetectionStrategy.OnPush - @Inputの値が変わった場合にのみ値の変更をチェック - 入力に変更がない場合は配下のチェックをスキップ → 効率が良い - 値の変更 = 参照の変更なので注意が必要 (@Inputにオブジェクトを渡している場合、内部の値が変わっても変更とはみなされな い) - ChangeDetectorRef.markForCheck()を使ってに任意に変更検知させることも可能。
本編はここまで
ここからは宣伝
ng-fukuoka 設立しました! 代表 puku0x 副代表 gupuru スタッフ mya-ake, ponday
ng-fukuoka 設立しました! 代表 puku0x 副代表 gupuru スタッフ mya-ake, ponday ?
初回イベントやります!
ng-fukuoka Angular Meetup #1