- TypeScript入門與實戰
- 鐘勝平編著
- 398字
- 2021-01-15 15:35:50
1.3.2 Angular
Angular是由Google公司推出的一款開源的Web應用程序框架。嚴格地講,當使用“Angular”這個名字時,我們指的是Angular 2.0及以上版本;而當使用“AngularJS”這個名字時,則特指Angular 1.x版本。不論是AngularJS還是Angular,它們都是非常流行的框架。
Angular使用TypeScript語言對AngularJS進行了完全重寫。關于Angular開發團隊選擇使用TypeScript語言進行重寫的原因,Angular工程總監Brad如是說道:“我們喜愛Type-Script的很多方面……”在使用了TypeScript后,一些團隊成員說:“現在我能夠真正理解我們的大多數代碼了!”因為他們能夠方便地在代碼之間導航并理解它們之間的關系。此外,我們已經利用TypeScript的檢查發現了一些Bug。
Angular團隊也推薦使用TypeScript語言作為Angular應用的首選開發語言。下面是一段Angular代碼示例:
01 /** 02 * Copyright Google LLC. All Rights Reserved. 03 * Use of this source code is governed by an MIT-style 04 * license that can be found in the LICENSE file 05 * at http://angular.io/license 06 */ 07 import { Component, OnInit } from '@angular/core'; 08 09 import { Hero } from '../hero'; 10 import { HeroService } from '../hero.service'; 11 12 @Component({ 13 selector: 'app-dashboard', 14 templateUrl: './dashboard.component.html', 15 styleUrls: ['./dashboard.component.css'], 16 }) 17 export class DashboardComponent implements OnInit { 18 heroes: Hero[] = []; 19 20 constructor(private heroService: HeroService) {} 21 22 ngOnInit() { 23 this.getHeroes(); 24 } 25 26 getHeroes(): void { 27 this.heroService.getHeroes().subscribe(heroes => { 28 this.heroes = heroes.slice(1, 5); 29 }); 30 } 31 }
推薦閱讀
- 流量的秘密:Google Analytics網站分析與優化技巧(第2版)
- Implementing Modern DevOps
- 零起步玩轉掌控板與Mind+
- Python網絡爬蟲從入門到實踐(第2版)
- Learn Scala Programming
- Building a Recommendation Engine with Scala
- 深度強化學習算法與實踐:基于PyTorch的實現
- 單片機應用與調試項目教程(C語言版)
- PHP從入門到精通(第4版)(軟件開發視頻大講堂)
- OpenCV with Python By Example
- Python入門很輕松(微課超值版)
- SQL Server 2008 R2數據庫技術及應用(第3版)
- Visual FoxPro 6.0程序設計
- 實戰Java高并發程序設計(第2版)
- Clojure High Performance Programming(Second Edition)