0
나는 다음과 같은 방법으로 사용 asynchron의 데이터로 작업 :비동기 데이터를 처리하는 더 좋고 더 짧은 방법이 있습니까?
서비스 :
app.service("DashboardService", function($resource, $q, APIService) {
return {
getLatestDevices: getLatestDevices,
}
function getLatestDevices() {
var d = $q.defer()
APIService.query({route: 'devices'}).$promise.then(function(data) {
d.resolve(data)
})
return d.promise
}
}
컨트롤러 :
app.controller("DashboardCtrl", function($scope, DashboardService) {
DashboardService.getLatestDevices().then(function(data){
$scope.latestDevices = data
})
})
이 할 수있는 더 나은 또는 더 짧은 방법이 있나요? 아니면 올바른 방법으로합니까? 감사합니다!
감사합니다. 내가 당신을 사용할 때 코드 ... 나는 나의 컨트롤러에서 다음과 같은 오류가 발생했다 : "TypeError : 속성을 읽을 수 없다 '다음에'정의되지 않은 것 ' – nofear87
Ups ... 반환 문제였다 ... 나는 첫 번째 리턴을 잊었다! – nofear87