一、angular:module-Controller-Model-View (模块-控制器-模型-视图);异步请求$http
.slide-in-up.ng-enter, .slide-in-up > .ng-enter { -webkit-transition: all cubic-bezier(.1, .7, .1, 1) 400ms; transition: all cubic-bezier(.1, .7, .1, 1) 400ms } .slide-in-up.ng-enter-active, .slide-in-up > .ng-enter-active { -webkit-transform: translate3d(0, 0, 0); transform: translate3d(0, 0, 0) } .slide-in-up.ng-leave, .slide-in-up > .ng-leave { -webkit-transition: all ease-in-out 250ms; transition: all ease-in-out 250ms }
1、在一个父元素上声明ng-app指令,确定Angular应用的作用范围。
2、使用angular.module('模块名', [依赖列表])创建一个模块
3、在模块中声明控制器 module.controller('控制器名', function(){ });控制器中对模型数据进行CRUD
4视图:<ANY>{{ 式子 }}</ANY>
(1){{}}可以输出各种数学/比较/逻辑/三目运算/调用string对象的方法/模型变量的值;
(2)但不能调用全局函数、不能创建对象、普通JS页面变量的值。
(3){{}}会发生元素内容闪动现象,可以使用ngBind指令解决此问题
5、异步请求数据:$http
dome:
angular.module('APP', ['ng'])
.controller('contro2', function ($scope, $http, $interval) {
$scope.salary = 800;
$scope.emp = [{ename: 'Tom', age: 20}, {ename: 'hai', age: 30}];
$scope.loadData = function () {
//发起异步的AJAX请求,获取服务器端数据
//ng/service/$http
$http.get('data/1.php')
.success(function (data) {
//console.log(data);//[Object,Object,Object]
//控制器只需要把得到的数据声明为“模型数据”,就可以绑定在页面中
//$scope.emp = data;
if (!$scope.emp) {
$scope.emp = [];
}
$scope.emp = $scope.emp.concat(data);
})
}
$interval(function () {
$scope.time = new Date().toLocaleTimeString();
}, 1000)
})
.controller('contor3', function ($scope) {
$scope.pel = [{name: "huge", age: 54, hoby: "sing"}, {
name: "huojianhua",
age: 54,
hoby: "act"
}, {name: "jiangliuer", age: 80, hoby: "skry"}]
})

浙公网安备 33010602011771号