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){//successthis.data=d;deferred.resolve(d);},function(){//failuredeferred.reject(d);});}});controller代碼:app.controller('projectController',function($scope,getTicketList){$scope.tickets=getTicketList.getData($scope.projectId).data.tickets;});controller的那句代碼有問(wèn)題。我用getTicketList.data也獲取不到數(shù)據(jù),是{}。而且不知道怎么把參數(shù)傳進(jìn)去。。。。
angularjs 如何在controller中使用service
慕田峪4524236
2019-04-07 11:18:24