框架: 對程序員的限制高
庫: jquery镜硕,bootstrap —— 使用靈活运翼,對程序員的限制少
它是MVC框架 精確定義是MVVM框架 mv*
SPA (single page application) 移動端
MVC:
Model(模型)表示應(yīng)用程序核心(比如數(shù)據(jù)庫記錄列表)。
View(視圖)顯示數(shù)據(jù)(數(shù)據(jù)庫記錄)兴枯。
Controller(控制器)處理輸入(寫入數(shù)據(jù)庫記錄)血淌。
MVC 分離:
1.數(shù)據(jù)、邏輯财剖、 表現(xiàn)層代碼的分離
2.分工
**學(xué)好:它最核心的核心的東西就是數(shù)據(jù)
以前寫JS:存在大量的重復(fù)勞動
window 事件 .....
Angular:避免了重復(fù)勞動悠夯,讓程序員更加關(guān)注需求的本質(zhì)和實(shí)現(xiàn)。
基本用法:
Angular指令:
以 ng 開頭躺坟。
是否需要服務(wù)器環(huán)境——最好
oninput是input值改變的時(shí)候觸發(fā)
1沦补、ng-app
angular管轄的范圍
2、ng-model
數(shù)據(jù)咪橙,數(shù)據(jù)模型—— 數(shù)據(jù)從哪來
3夕膀、ng-bind
數(shù)據(jù)綁定 —— 數(shù)據(jù)到哪去
4虚倒、表達(dá)式{{a}}
*Angular 和 原生的JS——不互通(事件、函數(shù))产舞,可以解決魂奥。
5、ng-click
事件: ng-mouseover ....
* 只關(guān)注數(shù)據(jù)
6庞瘸、ng-init
數(shù)據(jù)初始化
7捧弃、ng-repeat 循環(huán)
循環(huán)數(shù)組:
ng-repeat="item in arr"
{{item}} —— 數(shù)組中的每一項(xiàng)
循環(huán)JSON:
ng-repeat="(key,value) in json"
{{key}} —— json中的key
{{value}} —— json中的value
ng-repeat:
數(shù)組:
(key,value) in arr
key—— 索引
value —— 每一項(xiàng)
json:
(key,value) in json
key 鍵名
value 鍵值
8、數(shù)組的索引: $index 獲取本元素的索引
*在數(shù)組里擦囊,默認(rèn)情況下不允許出現(xiàn)重復(fù)的數(shù)字 如果有重復(fù)的會報(bào)錯(cuò)
track by 重新指定數(shù)組中的key
以前:(key,value) in arr
現(xiàn)在:item in arr track by $index
9违霞、過濾器 filter
currency : 貨幣的filter
參數(shù): currency:'¥'
date:
date:'yyyy MM dd HH(hh) mm ss'
Angular:
1、和原生的JS 是不互通 —— 可以得解決
2瞬场、和傳統(tǒng)的開發(fā)方式完全不同——只要盯住數(shù)據(jù)买鸽,數(shù)據(jù)是核心
不互通:
1)函數(shù)不互通
Number 示例
2)變量不互通
全局變量示例
3)事件不互通
MVC—— C
控制器: Controller
1)定義模塊
angular.module(模塊名,所依賴的其它模塊);
let mod = angular.module('mod1',[]);
2)引用模塊
ng-app="模塊名"
3)定義Controller
mod.controller('控制器名',回調(diào)函數(shù)($scope){
//控制器的代碼
});
4)引用controller
ng-controller="ctr1"
*所有的數(shù)據(jù)都放在$scope
$scope : 依賴項(xiàng)
Angular:
1)雙向綁定
2)依賴注入
Controller:
1)放代碼
2)原生和angular之間的橋梁 —— 在controller中可以使用原生代碼
*一個(gè)頁面中,可以有多個(gè)模塊
*在一個(gè)模塊中贯被,可以有多個(gè)控制器
*為什么不互通:因?yàn)閍ngular的東西都在$scope身上眼五。