发表于: 2016-08-25 11:10:43
1 2074
今天完成的事情:js8与查漏补缺
明天计划的事情:继续
遇到的问题:factory中$http获取内容:
1、在路由中
var myApp=angular.module('myApp',['ui.router','oc.lazyLoad']);
注入过了,所以在factory中
angular.module('myApp')
不能加[],否则会报错
factory中:
angular.module('myApp')
.factory('getStudents', function ($http) {
return {
http: $http({
url: 'ajax/students',
method: 'GET'
}).success(function (data) {
console.log('获取成功');
})
};
});
或者$http简写形式
$http.get('ajax/students');
controller中:
getStudents.http.then(function(res){
vm.studentsList=res.data.data;
console.log(vm.studentsList)
});
注:factory中还可以这样写
var factory={};
factory.aaa='aaaadas';
这样在控制器中
getStudents.aaa
即可
收获:(通过今天的学习,学到了什么知识)
评论