SlideShare a Scribd company logo
1 of 11
パソコン部活動報告
2015/03/31
最新の技術をとりあえず試
してみることを目的とした
部です。
2015/03月活動内容
1. angular.js1.3系を利用して再利用可能なディレクティブを作成する
Look at me mom...dad and I are having so much fun!
1.概要
1. 今回作る予定のディレクティブ
angularではDom要素の変更はdirectiveに任せる思想があるので、クリックした要素を強調してどれがおさせたかわかるよう
になるディレクティブを作成する。
最終的にはクリックしたObject情報を特定できるようにする。
完成イメージ化こちら
ちょっとわかりにくいけど、クリックすると灰色になる。
2.ディレクティブを考える
1. restrict
まずは、Directiveの運用方法を何にするかを考えてみる。
指定できるオプションは4つ。
いろいろと使いまわせるものにしたいのと、きっとリピート処理と一緒に使うことになるので、Aにすることにする。
A 属性名として利用可能
E 要素名として利用可能
C クラス名として利用可能
M コメントとして利用可能
2.ディレクティブを考える
2. scope
次はscopeの生成方法を考えてみる。
再利用を前提としたdirectiveは分離スコープにするべきとangularの偉い人が言ってたんで、分離スコープにする。
scopeに指定できるオプションは以下の3つ。
scopeの共有ってのは、指定されているコントローラーで利用されているscope(親scope)を共有すること。
派生したscopeを生成ってのは、指定されているコントローラーのscopeに属するscopeになるってこと。
つまり、scopeに対してdirectiveから直接アクセスできちゃうし、コントローラーで指定されたscopeを指定するってこと
は
そのscopeに依存しちゃう。
だからscopeを分離することで独立性を高めるわけです。
false 利用箇所のscopeを共有
true 利用箇所のscopeから派生したscopeを生成
オブジェクトリテラ
ル
分離スコープを生成
2.ディレクティブを考える
2. scope
分離スコープにするんだけど、利用するスコープのメンバにどういった属性を指定するかを考える。
指定できるのは以下の3つ。
想定する使い方はリピートされた要素に対して属性として指定するんだから、リピート要素をデータバインディングすれ
ばOK。
ここまでをコーディングするとこんな感じ
。
pushDirectiveってのは、このdirectiveの名称。
pushInfoがこのdirective内でアクセスするための
名称になって、infoがこのdirectiveを指定した要素側
でバインドする時に指定する名称。
@ 文字列として結びつける
= データバインディングとして結びつける
& functionとして結びつける
2.ディレクティブを考える
3. link
んじゃ、実際に指定された場合のことを考えてみる。
まず、読み込まれたら該当要素にclickイベントを設定しないとだめだよね。
clickイベントのfunctionで要素のCSSを変更すればOKだから、簡単にできそう。
そこで使うのがlink関数。こいつが実行される時にはscopeが生成されてる。
パラメータは全部で5つあるけど、今回は↓の3つだけで大丈夫。
scope directiveのscope
element 指定された要素
attrs 属性
2.ディレクティブを考える
3. link
ソースコードはこんな感じになる。
2.ディレクティブを考える
3. link
最後に分離スコープにクリックされた要素であることを設定する処理を追加する。
赤枠が追加した部分。
バインドされたオブジェクトにメンバを追加して
どれが押されたかがわかるようにした。
押されたのもの抽出は、コントローラーかサービス
側の仕事ということで。。。
3.ディレクティブを使う
1. HTMLに指定する
最後に、作ったディレクティブを使ってみる。
4.最後
1. HTMLに指定する
directiveには今回指定しなかった、オプションがまだまだある。
direcitveを作るうえでは、templeteオプション、templeteUrlオプション、compile関数は抑えておいたほうがいい。
あー、unityでクソゲー作りたくなってきた。

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

活動報告5 ~簡単なディレクティブを作る~

Editor's Notes

  1. Image Sources: http://www.flickr.com/photos/cat_bus/2436839379/sizes/l/ http://www.flickr.com/photos/chippenziedeutch/1338350448/sizes/l/ http://www.flickr.com/photos/17625613@N00/63534223/sizes/o/ http://www.flickr.com/photos/andy_bernay-roman/740526711/sizes/o/ http://www.flickr.com/photos/criminalintent/2246696077/sizes/l/ http://www.flickr.com/photos/criminalintent/2300328819/sizes/l/in/set-72157603816609718/ http://www.flickr.com/photos/criminalintent/2344482203/sizes/l/in/set-72157603816609718/ http://www.flickr.com/photos/billward/110319298/sizes/o/ http://www.flickr.com/photos/ginamig/2283868571/sizes/l/ http://www.flickr.com/photos/cochese/1388690893/sizes/o/