AngularJS – 基本介紹篇

看完上一篇有關AngularJS的文章之後,如果你已經產生對他的興趣,接下來我們就跟著Google規劃的課程來學習,其實在AngularJS的官方網頁上,本來就有這方面的視訊教學(當然是英文的囉!),馬老師這邊只是做到整理、翻譯和提出我的一些想法,讓想要學習他的人可以更方便,官方視訊總共分成五個等級,每個等級又分成不同章節,章節結束後還都會有模擬測驗,真的推薦大家可以去看看喔!

首先檢視一下要學習AngularJS的一些背景條件:

必須要了解

  • HTML、CSS
  • Javascript

最好能懂

不是那麼重要的

  • jQuery
  • Ruby
  • Rails
  • Python
  • PHP
  • Database

必須了解的部分指的是技術領域,最好能懂的部分是指開發時的觀念

AngularJS Part1 Slide1

至於選擇AngularJS的理由有以下幾點:

  • 幫助你組織Javascript
  • 快速幫你建構動態網站
  • 可以跟jQuery合作愉快
  • 便於測試
AngularJS Part1 Slide2

接下來官方教學以ng-controller為案例,教導AngularJS是如何去呼叫函數的,不過這部分在1.3以上的版本已經不是這樣使用了要特別注意!

AngularJS Part1 Slide3

以下就針對這個案例進行程式的示範,在1.2(含)以前的AngularJS可以這樣來操作ng-controller:(在JS Bin上測試

<!doctype html>
<html ng-app>
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
<meta charset="UTF-8">
<title>controllerExample</title>
<script>
  function myFn() {
    alert("歡迎光臨馬老師雲端研究室");
  }
</script>
</head>
<body ng-controller="myFn">
</body>
</html>

但在1.3(含)之後的AngularJS需要這樣來操作ng-controller:(在JS Bin上測試)

<!doctype html>
<html ng-app="controllerExample">
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script>
<meta charset="UTF-8">
<title>controllerExample AngularJS 1.3.2</title>
<script>
angular.module('controllerExample', [])
.controller('myFn', function (){
    alert("歡迎光臨馬老師雲端研究室");
});
</script>
</head>
<body ng-controller="myFn">
</body>
</html>

根據上面的案例,來介紹利用AngularJS開發網頁時的流程和方式:

首先我們可以先建立一個模組(Module),在模組內會包含AngularJS的函式名稱、應用程式名稱(Application Name)和相關函式庫(Dependencies)。

AngularJS Part1 Slide4

上述的程式可以撰寫在一個JS檔案中,讓網頁將該檔案引用。

AngularJS Part1 Slide5

接下來在HTML標籤中加入ng-app=”Application Name”後,讓網頁在載入的時候就會自動運行該模組(Module)。

AngularJS Part1 Slide6

接下來開始介紹表達式,不過這個在上一篇案例當中我們已經有使用過了,相信大家也很容易能夠了解,也建議大家去參考視訊中提到的網頁,裡面有更多有關於表達式的說明。

AngularJS Part1 Slide7

※以上截圖部分為AngularJS官方教學視訊

You may also like...

14,677 Responses

  1. Lelia表示:

    The Ultimate Cheat Sheet For Private Psychiatrist private psychiatrist yorkshire (Lelia)

  2. Если вы искали где отремонтировать сломаную технику, обратите внимание – выездной ремонт бытовой техники в уфе

  3. Mark表示:

    10 Mobile Apps That Are The Best For Portable Mobility Scooters branded mobility scooters – Mark,

  4. gamesontv.org表示:

    You’ll Never Be Able To Figure Out This Twin Stroller’s Benefits twin stroller
    (gamesontv.org)

  5. One other issue issue is that video games can be serious as the name indicated with the primary focus on understanding rather than amusement. Although, there is an entertainment facet to keep the kids engaged, just about every game will likely be designed to work with a specific group of skills or programs, such as math or scientific research. Thanks for your post.

  6. 221878.Xyz表示:

    Are Costa Beans The Best Thing There Ever Was?
    221878.xyz (221878.Xyz)

  7. 10 Tell-Tale Signals You Need To Know Before You
    Buy Auto Lock Smith Near Me Auto key Smith

  8. Edisonanazy表示:

    farmacia online piГ№ conveniente: Cialis generico farmacia – acquistare farmaci senza ricetta

  9. Профессиональный сервисный центр по ремонту бытовой техники с выездом на дом.
    Мы предлагаем: ремонт крупногабаритной техники в красноярске
    Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!

  10. Профессиональный сервисный центр по ремонту бытовой техники с выездом на дом.
    Мы предлагаем: ремонт бытовой техники в красноярске
    Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!

  11. Edisonanazy表示:

    comprare farmaci online con ricetta: Farmacia online piu conveniente – comprare farmaci online all’estero

  12. Sadye表示:

    How To Become A Prosperous Renault Master Key Replacement When You’re Not Business-Savvy renault kangoo van replacement key
    (Sadye)

  13. Freddie表示:

    Why Nobody Cares About Fiat 500 Key Fob fiat 500 key cover uk (Freddie)

  14. At this time it seems like BlogEngine is the best blogging platform out there right now. (from what I’ve read) Is that what you’re using on your blog?

  15. bong da lu表示:

    Bongdalu cập nhật tin tức bóng đá nóng hổi, thể thao sôi động và giải trí hấp dẫn.

  16. Five Assessments For Adhd Lessons From The Professionals should i get an adhd assessment

  17. Clement表示:

    Guide To Treadmill Used For Sale: The Intermediate Guide For Treadmill
    Used For Sale treadmill used for sale; Clement,

  18. Профессиональный сервисный центр по ремонту парогенераторов в Москве.
    Мы предлагаем: ремонт парогенератора
    Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!

  19. Clayton表示:

    13 Things You Should Know About Assessment For Adhd In Adults That You Might Never Have Known adult adhd assessment london (Clayton)

  20. It’s A What Causes Mesothelioma Other Than Asbestos Success
    Story You’ll Never Believe mesothelioma lawyer

  21. mot chill表示:

    Motchilltv.fyi – Trang web xem phim Online chất lượng Full HD với giao diện thân thiện, trực quan cùng kho phim với hơn 15.000+ bộ phim mới và phim hot hiện nay.

  22. The 10 Most Terrifying Things About Patio Doors Repairs Near Me patio doors repairs Near Me

  23. 10 Silicone Anal Plug That Are Unexpected Adult Anal Toys

  24. My brother suggested I might like this blog. He was entirely right. This post actually made my day. You can not imagine simply how much time I had spent for this info! Thanks!

  25. Burst pipes表示:

    Dead written subject matter, Really enjoyed examining .

  26. Florine表示:

    This Is The Advanced Guide To Situs Terpercaya situs togel terpercaya, Florine,

  27. Edisonanazy表示:

    comprare farmaci online all’estero: Cialis generico recensioni – Farmacie online sicure

  28. Basil表示:

    The Top 5 Reasons People Thrive In The Integrated Fridge Freezer Frost Free 50/50 Industry 500mm
    integrated fridge (Basil)

  29. Edisonanazy表示:

    farmacia online senza ricetta: Cialis generico 20 mg 8 compresse prezzo – comprare farmaci online all’estero

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。