SlideShare a Scribd company logo
快快樂樂學 Angular 2 開發框架
多奇數位創意有限公司
技術總監 黃保翕 ( Will 保哥 )
部落格:http://blog.miniasp.com/
新手上路之 40 分鐘學會 Angular 2 網站開發框架
ANGULAR 2 簡介
Angular 2 Introduction
Angular 2 新特色
• 效能改進 (Performance)
– 偵測變更:比 ng1 快 10 倍
– 渲染速度:比 ng1 快 5 倍 (Render & Re-render)
– 範本編譯:支援 Template 預先編譯機制
– 更小的 Library Size 與延遲載入機制
– 支援伺服器渲染機制 (Node.js & ASP.NET )
• 高生產力 (Productivity)
– 開發應用程式能夠用更簡潔的語法讓團隊更加容易上手跟維護
– 更強大的開發工具 Augury
– 移除超過 40+ 個 directives
• 多樣平台 (Versatility)
– 支援 Browser, Node.js, NativeScript, and more … 3
從框架轉向平台
4
Angular 2 的開發語言
TypeScrip
t
ES 2016
ES 2015
ES5
5
Angular 2 的開發語言
• ES5
– 傳統 JavaScript 程式語言 ( IE9+ )
• ES 2015
– 此版本為 ES5 的「超集合」
– 具有新穎的 JavaScript 語言特性 ( let, const, for-of, … )
– 可透過 Babel 轉譯器將瀏覽器不支援的語法轉為 ES5 版本
• TypeScript
– 此版本為 ES 2015 的「超集合」
– 具有強型別特性、內建 ES5 轉譯器 (Transpiler)、更好的工具支
援
• Dart
– 非 JavaScript 家族的程式語言
– 具有強型別特性 6
Angular 2 的開發工具
• Visual Studio Code
• Visual Studio 2015
• Sublime Text
• WebStorm
• Atom
• Plunker
7
Angular 2 應用程式的組成
• App Component元件
• Child Component元件
• Services Component元件
• Pipe Component元件
Angular 2 頁面的組成
應用程式元件 + 樣板 + 樣式
( AppComponent )
頁首元件 + 樣板 + 樣式
( HeaderComponent )
子選單
元件 + 樣板 + 樣式
(AsideComponent)
9
主要內容
元件 + 樣板 + 樣式
(ArticleComponent)
Angular 2 結構剖析
10
Angular 2 結構剖析
• Module 應用程式被切分成許多「模組」
• Component 每個模組下有許多「元件」
• Template 每個元件都可能有自己的「樣板」
• Metadata 每個元件都可以標示「中繼資料」
• Data Binding 樣板與元件屬性、方法可以進行綁定
• Directive 將 DOM 轉換為多功能的「宣告命令」
• Service 由「服務」集中管理資料與運算邏輯
• Dependency Injection 由「相依注入」機制管理物件生命週期
11
Angular 2 元件的組成
範本
( Template )
• HTML 版面配置
• HTML 部分片段
• 資料繫結 (Bindings)
• 畫面命令 (Directives)
類別
( Class )
• 建構式 (Constructor)
• 屬性 (Properties)
• 方法 (Methods)
中繼資料
( Metadata )
• 裝飾器 (Decorator)
• 針對類別
• 針對屬性
• 針對方法
• 針對參數
12
建立 ANGULAR 2 應用程式
Build your Angular 2 Application
13
準備開發環境
• 完整移除 Node.js 的方法 (Windows)
– 先手動移除 Node.js 應用程式
– del "%USERPROFILE%.npmrc"
– rmdir /s/q "C:Program Filesnodejs"
– rmdir /s/q "%APPDATA%npm"
– rmdir /s/q "%APPDATA%npm-cache"
• 安裝 Node.js v6.2.2 (npm3) 與 Visual Studio Code
• 安裝必備 npm 套件
– npm install -g gulp yo webpack rimraf
– npm install -g typescript typings angular-cli
– npm install -g eslint tslint
14
使用 Angular CLI 建立專案範本
• 請務必在 NTFS 檔案系統執行相關命令 (Windows)
• ng new demo1
– 初始化 Git 儲存庫
– 安裝 npm 相依套件
• cd demo1
• npm install ( 這是 1.0.0-beta.8 已知問題 )
– Error: Cannot find module 'exists-sync'
• ng build
• ng serve (若加上 -prod 同時也會關閉 Live Reload)
– http://localhost:4200
– http://localhost:49152 (Live Reload)
• ng generate component header
• ng generate service search
15
了解專案結構
• 首頁
– src/index.html 預設網站首頁
• 啟動器
– src/main.ts 預設 Angular 2 啟動器
• 根元件
– src/app/index.ts 載入根元件的預設檔
– src/app/environment.ts 環境變數設定
– src/app/app.component.ts 根元件主程式
– src/app/app.component.spec.ts 單元測試定義檔
– src/app/app.component.html 根元件範本檔
(Template)
– src/app/app.component.css 根元件樣式檔 (CSS)
– src/app/shared/index.ts 根元件的相關服務元件
16
資料繫結的四種方法 (Binding syntax)
• 內嵌繫結 ( interpolation )
{{property}}
• 屬性繫結 ( Property Binding )
[property]='statement'
• 事件繫結 ( Event Binding )
(event)='someMethod($event)'
• 雙向繫結 ( Two-way Binding )
[(ngModel)]='property'
17
結構式命令 (Structure Directives)
• 判斷式
*ngIf='products && products.length'
ngSwitch / ngSwitchWhen / ngSwitchDefault
• 迴圈
*ngFor='let product of products'
18
相關連結
• 今日 Live Demo 原始碼
https://github.com/doggy8088/ctjs2016-ng2demo
– 完整開發歷程記錄 (含每個版本註解)
https://github.com/doggy8088/ctjs2016-ng2demo/commits/master
– 現場 demo code 完整版
https://github.com/doggy8088/ctjs2016-ng2demo/commits/livedemo
• Angular 2 官網
• Angular 2 官網 - 簡體中文翻譯 (高品質)
• Angular CLI (命令列工具)
• ReactiveX ( RxJS on GitHub )
• RxMarbles: Interactive diagrams of Rx Observables
• TypeScript - JavaScript that scales.
• TypeScript Handbook (中文版)
19
聯絡資訊
• The Will Will Web
記載著 Will 在網路世界的學習心得與技術分享
– http://blog.miniasp.com/
• Will 保哥的技術交流中心 (臉書粉絲專頁)
– http://www.facebook.com/will.fans
• Will 保哥的噗浪
– http://www.plurk.com/willh/invite
• Will 保哥的推特
– https://twitter.com/Will_Huang

More Related Content

What's hot (20)

PDF
Isn't it ironic - managing a bare metal cloud (OSL TES 2015)
Devananda Van Der Veen
 
PPTX
How To Become A DevOps Engineer | Who Is A DevOps Engineer? | DevOps Engineer...
Simplilearn
 
PDF
Unreal Engine 5 早期アクセスの注目機能総おさらい Part 2
エピック・ゲームズ・ジャパン Epic Games Japan
 
PDF
P2P Container Image Distribution on IPFS With containerd and nerdctl
Kohei Tokunaga
 
PDF
Embedded Android Workshop
Opersys inc.
 
PDF
Improve Android System Component Performance
National Cheng Kung University
 
PDF
Docker入門-基礎編 いまから始めるDocker管理【2nd Edition】
Masahito Zembutsu
 
PDF
Advance linux presentation_0702011
Aravindan Arun
 
PPTX
HoloLens2とPCで、WebRTCで映像をやりとり
聡 大久保
 
KEY
Google I/O 2011, Android Accelerated Rendering
Romain Guy
 
PPT
Android booting sequece and setup and debugging
Utkarsh Mankad
 
PPTX
Android組込み開発基礎コース Armadillo-440編
OESF Education
 
PPTX
Photon Fusionのはじめの一歩
聡 大久保
 
PDF
1. Docker Introduction.pdf
AmarGautam15
 
PDF
Introduction to Docker Compose
Ajeet Singh Raina
 
PDF
AndroidとSELinux
android sola
 
PDF
Kubernetes 101
Winton Winton
 
PPT
Version Control System
guptaanil
 
PPTX
Docker, Docker Compose and Docker Swarm
Carlos E. Salazar
 
Isn't it ironic - managing a bare metal cloud (OSL TES 2015)
Devananda Van Der Veen
 
How To Become A DevOps Engineer | Who Is A DevOps Engineer? | DevOps Engineer...
Simplilearn
 
Unreal Engine 5 早期アクセスの注目機能総おさらい Part 2
エピック・ゲームズ・ジャパン Epic Games Japan
 
P2P Container Image Distribution on IPFS With containerd and nerdctl
Kohei Tokunaga
 
Embedded Android Workshop
Opersys inc.
 
Improve Android System Component Performance
National Cheng Kung University
 
Docker入門-基礎編 いまから始めるDocker管理【2nd Edition】
Masahito Zembutsu
 
Advance linux presentation_0702011
Aravindan Arun
 
HoloLens2とPCで、WebRTCで映像をやりとり
聡 大久保
 
Google I/O 2011, Android Accelerated Rendering
Romain Guy
 
Android booting sequece and setup and debugging
Utkarsh Mankad
 
Android組込み開発基礎コース Armadillo-440編
OESF Education
 
Photon Fusionのはじめの一歩
聡 大久保
 
1. Docker Introduction.pdf
AmarGautam15
 
Introduction to Docker Compose
Ajeet Singh Raina
 
AndroidとSELinux
android sola
 
Kubernetes 101
Winton Winton
 
Version Control System
guptaanil
 
Docker, Docker Compose and Docker Swarm
Carlos E. Salazar
 

Viewers also liked (6)

PPTX
Http Headers 與 Cache 機制(2016)
振揚 陳
 
PPTX
初學者都該了解的 HTTP 通訊協定基礎
Will Huang
 
PPTX
Http cache 的優化
振揚 陳
 
PDF
帶領團隊討論與思考,從學「問」開始
Steven Tseng
 
PDF
ORID焦點討論法 - 白話入門篇
Chuang Shu-Ting
 
PPTX
TypeScript 綜合格鬥技
Will Huang
 
Http Headers 與 Cache 機制(2016)
振揚 陳
 
初學者都該了解的 HTTP 通訊協定基礎
Will Huang
 
Http cache 的優化
振揚 陳
 
帶領團隊討論與思考,從學「問」開始
Steven Tseng
 
ORID焦點討論法 - 白話入門篇
Chuang Shu-Ting
 
TypeScript 綜合格鬥技
Will Huang
 
Ad

Similar to 快快樂樂學 Angular 2 開發框架 (19)

PPTX
快快樂樂學會 Angular 2 網站開發框架 (Modern Web 2016)
Will Huang
 
PPTX
Angular 7 全新功能探索 (Angular Taiwan 2018)
Will Huang
 
PPTX
Angular 5 全新功能探索 @ JSDC2017
Will Huang
 
PPTX
Angular 4 新手入門攻略完全制霸
Will Huang
 
PPTX
從前端設計的角度來看 Angular - TW2018 amos
Amos Lee
 
PDF
北護樂學程式冬令營 2017
Hamilton Wong
 
PPTX
快速入坑 Node.js - 0613 SITCON 雲林定期聚
Lorex L. Yang
 
PPTX
Angular 4 網站開發最佳實務 (Modern Web 2017)
Will Huang
 
PPTX
改善 Angular 開發流程:你所不知道的 Schematics 程式碼產生器
Chieh Kai Yang
 
PDF
Angular js 2 概論
Jou-An Lai
 
PPTX
ASP.NET MVC 6 新功能探索
Will Huang
 
PDF
JavaScript 快速複習 2017Q1
Sheng-Han Su
 
PDF
Angular從入門到實戰(二)
志龍 陳
 
PDF
Node.js從無到有 基本課程
Simon Su
 
PDF
Javascript
Ryan Chung
 
PPTX
前端自動化工具
國昭 張
 
PDF
程式人雜誌 -- 2013年7月號
鍾誠 陳鍾誠
 
PDF
程式人雜誌 -- 2013年8月號
鍾誠 陳鍾誠
 
PPTX
JavaScript 物件導向觀念入門 v.s. TypeScript 開發實戰 (微軟實戰課程日)
Will Huang
 
快快樂樂學會 Angular 2 網站開發框架 (Modern Web 2016)
Will Huang
 
Angular 7 全新功能探索 (Angular Taiwan 2018)
Will Huang
 
Angular 5 全新功能探索 @ JSDC2017
Will Huang
 
Angular 4 新手入門攻略完全制霸
Will Huang
 
從前端設計的角度來看 Angular - TW2018 amos
Amos Lee
 
北護樂學程式冬令營 2017
Hamilton Wong
 
快速入坑 Node.js - 0613 SITCON 雲林定期聚
Lorex L. Yang
 
Angular 4 網站開發最佳實務 (Modern Web 2017)
Will Huang
 
改善 Angular 開發流程:你所不知道的 Schematics 程式碼產生器
Chieh Kai Yang
 
Angular js 2 概論
Jou-An Lai
 
ASP.NET MVC 6 新功能探索
Will Huang
 
JavaScript 快速複習 2017Q1
Sheng-Han Su
 
Angular從入門到實戰(二)
志龍 陳
 
Node.js從無到有 基本課程
Simon Su
 
Javascript
Ryan Chung
 
前端自動化工具
國昭 張
 
程式人雜誌 -- 2013年7月號
鍾誠 陳鍾誠
 
程式人雜誌 -- 2013年8月號
鍾誠 陳鍾誠
 
JavaScript 物件導向觀念入門 v.s. TypeScript 開發實戰 (微軟實戰課程日)
Will Huang
 
Ad

More from Will Huang (20)

PPTX
深入理解 CVE-2022-24765 漏洞的攻擊與防護策略 (Git v2.35.2)
Will Huang
 
PPTX
從頭打造 C#、.NET 與 ASP.NET Core 開發環境
Will Huang
 
PPTX
ASP.NET Core 6.0 全新功能探索
Will Huang
 
PPTX
進擊的前端工程師:今天就用 JSON Server 自己打造 API 吧!
Will Huang
 
PPTX
你一定不能不知道的 Markdown 寫作技巧
Will Huang
 
PPTX
使用 .NET 5 實現美股期貨的量化交易策略 (.NET Conf 2020)
Will Huang
 
PPTX
實現 Angular, Docker 與 Kubernetes 持續部署 (NG+2020)
Will Huang
 
PPTX
Micro-frontends with Angular 10 (Modern Web 2020)
Will Huang
 
PPTX
從實戰經驗看到的 K8S 導入痛點
Will Huang
 
PPTX
RxJS 6 新手入門
Will Huang
 
PPTX
极速 Angular 开发:效能调校技巧 (ngChina 2019)
Will Huang
 
PPTX
你不可不知的 ASP.NET Core 3 全新功能探索 (.NET Conf 2019)
Will Huang
 
PPTX
Protractor: The Hacker way (NG-MY 2019)
Will Huang
 
PPTX
邁向 Windows Server 應用程式現代化 (Windows Server Application Modernization)
Will Huang
 
PPTX
Angular 开发技巧 (2018 ngChina 开发者大会)
Will Huang
 
PPTX
利用.NET Core 與 Azure Kubernetes Service (AKS) 建立高彈性 Microservices (Azure TechDay)
Will Huang
 
PPTX
AKS 與開發人員體驗 (Kubernetes 大講堂)
Will Huang
 
PPTX
使用 ASP.NET Blazor 開發 SPA 網頁應用程式 (.NET Conf 2018)
Will Huang
 
PPTX
全新 Windows Server 2019 容器技術 及邁向與 Kubernetes 整合之路 (Windows Server 高峰會)
Will Huang
 
PPTX
使用 C#/Razor 開發互動式 WebAssembly 網站 (Modern Web 2018)
Will Huang
 
深入理解 CVE-2022-24765 漏洞的攻擊與防護策略 (Git v2.35.2)
Will Huang
 
從頭打造 C#、.NET 與 ASP.NET Core 開發環境
Will Huang
 
ASP.NET Core 6.0 全新功能探索
Will Huang
 
進擊的前端工程師:今天就用 JSON Server 自己打造 API 吧!
Will Huang
 
你一定不能不知道的 Markdown 寫作技巧
Will Huang
 
使用 .NET 5 實現美股期貨的量化交易策略 (.NET Conf 2020)
Will Huang
 
實現 Angular, Docker 與 Kubernetes 持續部署 (NG+2020)
Will Huang
 
Micro-frontends with Angular 10 (Modern Web 2020)
Will Huang
 
從實戰經驗看到的 K8S 導入痛點
Will Huang
 
RxJS 6 新手入門
Will Huang
 
极速 Angular 开发:效能调校技巧 (ngChina 2019)
Will Huang
 
你不可不知的 ASP.NET Core 3 全新功能探索 (.NET Conf 2019)
Will Huang
 
Protractor: The Hacker way (NG-MY 2019)
Will Huang
 
邁向 Windows Server 應用程式現代化 (Windows Server Application Modernization)
Will Huang
 
Angular 开发技巧 (2018 ngChina 开发者大会)
Will Huang
 
利用.NET Core 與 Azure Kubernetes Service (AKS) 建立高彈性 Microservices (Azure TechDay)
Will Huang
 
AKS 與開發人員體驗 (Kubernetes 大講堂)
Will Huang
 
使用 ASP.NET Blazor 開發 SPA 網頁應用程式 (.NET Conf 2018)
Will Huang
 
全新 Windows Server 2019 容器技術 及邁向與 Kubernetes 整合之路 (Windows Server 高峰會)
Will Huang
 
使用 C#/Razor 開發互動式 WebAssembly 網站 (Modern Web 2018)
Will Huang
 

快快樂樂學 Angular 2 開發框架

  • 1. 快快樂樂學 Angular 2 開發框架 多奇數位創意有限公司 技術總監 黃保翕 ( Will 保哥 ) 部落格:http://blog.miniasp.com/ 新手上路之 40 分鐘學會 Angular 2 網站開發框架
  • 2. ANGULAR 2 簡介 Angular 2 Introduction
  • 3. Angular 2 新特色 • 效能改進 (Performance) – 偵測變更:比 ng1 快 10 倍 – 渲染速度:比 ng1 快 5 倍 (Render & Re-render) – 範本編譯:支援 Template 預先編譯機制 – 更小的 Library Size 與延遲載入機制 – 支援伺服器渲染機制 (Node.js & ASP.NET ) • 高生產力 (Productivity) – 開發應用程式能夠用更簡潔的語法讓團隊更加容易上手跟維護 – 更強大的開發工具 Augury – 移除超過 40+ 個 directives • 多樣平台 (Versatility) – 支援 Browser, Node.js, NativeScript, and more … 3
  • 6. Angular 2 的開發語言 • ES5 – 傳統 JavaScript 程式語言 ( IE9+ ) • ES 2015 – 此版本為 ES5 的「超集合」 – 具有新穎的 JavaScript 語言特性 ( let, const, for-of, … ) – 可透過 Babel 轉譯器將瀏覽器不支援的語法轉為 ES5 版本 • TypeScript – 此版本為 ES 2015 的「超集合」 – 具有強型別特性、內建 ES5 轉譯器 (Transpiler)、更好的工具支 援 • Dart – 非 JavaScript 家族的程式語言 – 具有強型別特性 6
  • 7. Angular 2 的開發工具 • Visual Studio Code • Visual Studio 2015 • Sublime Text • WebStorm • Atom • Plunker 7
  • 8. Angular 2 應用程式的組成 • App Component元件 • Child Component元件 • Services Component元件 • Pipe Component元件
  • 9. Angular 2 頁面的組成 應用程式元件 + 樣板 + 樣式 ( AppComponent ) 頁首元件 + 樣板 + 樣式 ( HeaderComponent ) 子選單 元件 + 樣板 + 樣式 (AsideComponent) 9 主要內容 元件 + 樣板 + 樣式 (ArticleComponent)
  • 11. Angular 2 結構剖析 • Module 應用程式被切分成許多「模組」 • Component 每個模組下有許多「元件」 • Template 每個元件都可能有自己的「樣板」 • Metadata 每個元件都可以標示「中繼資料」 • Data Binding 樣板與元件屬性、方法可以進行綁定 • Directive 將 DOM 轉換為多功能的「宣告命令」 • Service 由「服務」集中管理資料與運算邏輯 • Dependency Injection 由「相依注入」機制管理物件生命週期 11
  • 12. Angular 2 元件的組成 範本 ( Template ) • HTML 版面配置 • HTML 部分片段 • 資料繫結 (Bindings) • 畫面命令 (Directives) 類別 ( Class ) • 建構式 (Constructor) • 屬性 (Properties) • 方法 (Methods) 中繼資料 ( Metadata ) • 裝飾器 (Decorator) • 針對類別 • 針對屬性 • 針對方法 • 針對參數 12
  • 13. 建立 ANGULAR 2 應用程式 Build your Angular 2 Application 13
  • 14. 準備開發環境 • 完整移除 Node.js 的方法 (Windows) – 先手動移除 Node.js 應用程式 – del "%USERPROFILE%.npmrc" – rmdir /s/q "C:Program Filesnodejs" – rmdir /s/q "%APPDATA%npm" – rmdir /s/q "%APPDATA%npm-cache" • 安裝 Node.js v6.2.2 (npm3) 與 Visual Studio Code • 安裝必備 npm 套件 – npm install -g gulp yo webpack rimraf – npm install -g typescript typings angular-cli – npm install -g eslint tslint 14
  • 15. 使用 Angular CLI 建立專案範本 • 請務必在 NTFS 檔案系統執行相關命令 (Windows) • ng new demo1 – 初始化 Git 儲存庫 – 安裝 npm 相依套件 • cd demo1 • npm install ( 這是 1.0.0-beta.8 已知問題 ) – Error: Cannot find module 'exists-sync' • ng build • ng serve (若加上 -prod 同時也會關閉 Live Reload) – http://localhost:4200 – http://localhost:49152 (Live Reload) • ng generate component header • ng generate service search 15
  • 16. 了解專案結構 • 首頁 – src/index.html 預設網站首頁 • 啟動器 – src/main.ts 預設 Angular 2 啟動器 • 根元件 – src/app/index.ts 載入根元件的預設檔 – src/app/environment.ts 環境變數設定 – src/app/app.component.ts 根元件主程式 – src/app/app.component.spec.ts 單元測試定義檔 – src/app/app.component.html 根元件範本檔 (Template) – src/app/app.component.css 根元件樣式檔 (CSS) – src/app/shared/index.ts 根元件的相關服務元件 16
  • 17. 資料繫結的四種方法 (Binding syntax) • 內嵌繫結 ( interpolation ) {{property}} • 屬性繫結 ( Property Binding ) [property]='statement' • 事件繫結 ( Event Binding ) (event)='someMethod($event)' • 雙向繫結 ( Two-way Binding ) [(ngModel)]='property' 17
  • 18. 結構式命令 (Structure Directives) • 判斷式 *ngIf='products && products.length' ngSwitch / ngSwitchWhen / ngSwitchDefault • 迴圈 *ngFor='let product of products' 18
  • 19. 相關連結 • 今日 Live Demo 原始碼 https://github.com/doggy8088/ctjs2016-ng2demo – 完整開發歷程記錄 (含每個版本註解) https://github.com/doggy8088/ctjs2016-ng2demo/commits/master – 現場 demo code 完整版 https://github.com/doggy8088/ctjs2016-ng2demo/commits/livedemo • Angular 2 官網 • Angular 2 官網 - 簡體中文翻譯 (高品質) • Angular CLI (命令列工具) • ReactiveX ( RxJS on GitHub ) • RxMarbles: Interactive diagrams of Rx Observables • TypeScript - JavaScript that scales. • TypeScript Handbook (中文版) 19
  • 20. 聯絡資訊 • The Will Will Web 記載著 Will 在網路世界的學習心得與技術分享 – http://blog.miniasp.com/ • Will 保哥的技術交流中心 (臉書粉絲專頁) – http://www.facebook.com/will.fans • Will 保哥的噗浪 – http://www.plurk.com/willh/invite • Will 保哥的推特 – https://twitter.com/Will_Huang