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
130
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Angularのコンポーネントを知る
Angular触ろうの会 in Fukuoka #2(2017/05/29)の発表資料です。
ponday
May 29, 2017
More Decks by ponday
See All by ponday
関数型でGoFのデザインパターンやってみる
honda
1
1.6k
TypeScriptの型表現
honda
10
3.1k
Web Componentsの今
honda
1
480
これまでのReact、これからのReact
honda
0
340
Gatsbyお試し
honda
0
140
styled-components or emotion?
honda
0
720
Web ComponentsとAngular
honda
0
160
Atomic Design周りについての私見
honda
1
800
え、まだWeb Componentsを未来の技術だと思ってるの?
honda
2
880
Other Decks in Programming
See All in Programming
Language Server 使ってる? 〜VSCode と Zed の場合〜 / Are you using a Language Server? ~For VS Code and Zed~
handlename
0
790
RTSPクライアントを自作してみた話
simotin13
0
610
Signal Forms: Details & Live Coding @enterJS 2026 in Mannheim
manfredsteyer
PRO
0
150
正しくソフトウェアを作る、前提を疑うための認知の視点 / doubt-premise
minodriven
21
6.7k
Oxlintのカスタムルールの現況
syumai
6
1.1k
スマートグラスで並列バイブコーディング
hyshu
0
150
Javaの型とAI時代に型が大事な理由 / java types and type in AI era
kishida
2
140
3Dシーンの圧縮
fadis
1
780
ふつうのFeature Flag実践入門
irof
7
4k
AIとASP.NET Coreで雑Webアプリを作った話
mayuki
0
650
軽量Java基盤の設計 DIコンテナに頼らない、長期保守と1秒起動の実現 JJUG CCC 2026 Spring
macha64
0
540
Lemonade + Foundry Toolkit でお手軽アプリ開発
seosoft
1
360
Featured
See All Featured
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.5k
Fashionably flexible responsive web design (full day workshop)
malarkey
408
66k
The Curse of the Amulet
leimatthew05
1
13k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
220
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
340
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.2k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.5k
Reality Check: Gamification 10 Years Later
codingconduct
0
2.2k
Building a Scalable Design System with Sketch
lauravandoore
463
34k
From π to Pie charts
rasagy
0
210
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
630
Typedesign – Prime Four
hannesfritz
42
3.1k
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