1.干什么
重復勞動——獲取作彤、事件晚顷、創(chuàng)建
接管 UI
2.好在哪兒
自動同步
a.節(jié)約精力——放在更重要的事情上
b.規(guī)范整體開發(fā)
3.限制’
官網
https://angularjs.org/
庫:人在用庫
方便程序員
框架:框架在用人
限制程序員
MVC:
M-Model 模型-數(shù)據(jù)
V-View 視圖-表現(xiàn)層
C-controller 控制器-邏輯處理/業(yè)務邏輯
數(shù)據(jù)扎唾、表現(xiàn)分離
AngularJS是MVC框架
1.一切都是數(shù)據(jù)
2.是個“框架’’
AngularJS三要素:
1.ng-model:數(shù)據(jù)從哪來
2.ng-bind:數(shù)據(jù)到哪去
3.ng-app:那塊歸angular管
模板
Angular和原生JS 不互通——兩套
原生JS部分東西 angular 用不了
數(shù)據(jù)多了就不行了
controller
MVC:
M——ng-model
V——{{}}
C——controller
controller:
1.橋梁
2.業(yè)務邏輯
ng-app主要用來引入angular這個模塊
說到模塊首先要定義,然后在引用。
var mod=angular.module('');
模塊取個名字main_mod;
定義模塊
var mod=angular.module('main_mod',[依賴于什么模塊 ]);
引用模塊
ng-app="main_module"
ng-app這里面所有的東西歸這個模塊管
往模塊里添加東西裸违。
scope:范圍 作用域
mod.controller('control1',function($scope){
//controller 代碼都放這里
// $scope——所有angular數(shù)據(jù)都在scope身上
$scope.a=12
$scope.parseInt= function(n){
return parseInt(n);
};
});
ng-controller="control1"
{{parseInt(a)+parseInt(b)}} 生效
雙向綁定?
雙向-可進可出
輸入框——既可以輸入本昏,又可以輸出
*所有的數(shù)據(jù)是雙向的
數(shù)據(jù) <-> UI
依賴注入供汛?
把依賴項注入進去
函數(shù):函數(shù)的參數(shù)由定義的人決定的?還是調用的人決定的涌穆?
正常函數(shù)的參數(shù)是由調用的人決定的怔昨。
“依賴反轉”
angular里函數(shù)要什么參數(shù)就有什么參數(shù)。
是由定義的函數(shù)來決定的宿稀。好處在于用什么請求什么趁舀。
mod.controller('control1',function($scope,$http){
alert(arguments.length)
//結果是2
});