angularjs 如何在controller中使用service

Service代码:
app.service('getTicketList',function($q,$http){
this.data={};
this.getData=function(id){
vardeferred=$q.defer();
varpath='ticket.action?method:projectTickets';
if(id)
path+='&projectId='+id.toString();
$http.get(path).then(function(d){
//success
this.data=d;
deferred.resolve(d);
},function(){
//failure
deferred.reject(d);
});
}
});
controller代码:
app.controller('projectController',function($scope,getTicketList){
$scope.tickets=getTicketList.getData($scope.projectId).data.tickets;
});
controller的那句代码有问题。我用getTicketList.data也获取不到数据,是{}。而且不知道怎么把参数传进去。。。。
慕姐4208626
浏览 326回答 2
2回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript