Angular:
框架: 對程序員的限制高
庫: jquery转捕,bootstrap —— 使用靈活刃跛,對程序員的限制少
它是MVC框架 精確定義是MVVM框架 mv*
SPA (single page application) 移動(dòng)端
MVC:
M: Model 模型——數(shù)據(jù)
V: View 視圖
C: Controller 控制器
MVC 分離:
1.數(shù)據(jù)贷币、邏輯衬浑、 表現(xiàn)層代碼的分離
2.分工
**學(xué)好:它最核心的核心的東西就是數(shù)據(jù)
以前寫JS:存在大量的重復(fù)勞動(dòng)
window 事件 .....
Angular:避免了重復(fù)勞動(dòng)婆瓜,讓程序員更加關(guān)注需求的本質(zhì)和實(shí)現(xiàn)笑陈。
版本:
官網(wǎng):https://angularjs.org/
混亂:
1.2 以下
1.3 以上 上課
2.x 沒人用 angular2
3.x 消失
4.x 即將要出來
基本用法:
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ù)到哪去
MVC:
M: model 模型蓬网,數(shù)據(jù)——現(xiàn)在的例子中: 輸入框
V: view 視圖 ——現(xiàn)在的例子中: div
C:
Angular特性:
1).雙向綁定
ng-bind: 不好 一開始清空內(nèi)容
*Angular——接管了 UI
*Angular——擴(kuò)展了html
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ù)的會(huì)報(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'
放 | 后面
總結(jié):
ng-app
ng-model
ng-bind
{{}}
ng-repeat
ng-click
ng-init
$index
item in arr track by $index
currency
yyyy年MM月dd日 HH(hh) mm ss
10、ng-show ng-hide
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身上问慎。
總結(jié):
mvc
ng-app
ng-model
ng-bind
ng-init
ng-repeat
ng-click
ng-hide
ng-show
{{}}
$index
filter
track by
ng-controller
angular.module('app',[])
.controller('ctrl',($scope)=>{
})