이 코드가 있습니다defer.promise 객체가 아닌 데이터를 인쇄
app.factory('loadDependencies', function ($q, $timeout) {
return {
load: function() {
console.log("start 1");
var defer = $q.defer();
$timeout(function() {
defer.resolve({ resolve: "got dependencies" });
}, 3000);
return defer.promise;
}
}
});
을 그러나 문제는 제한 시간이 끝날 때까지 기다리지 않는 defer.promise이며, 또한 단지 객체 properteis에서 인쇄 데이터가 아니라면, 다음과 같이 인쇄하십시오.
Object { then: qFactory/defer/deferred.promise.then(), catch: qFactory/defer/deferred.promise.catch(), finally: qFactory/defer/deferred.promise.finally() }
내가 뭘 잘못했는지 이해하려고합니까?
편집
난 달성하기 위해 노력했다에 대한 몇 가지 추가 정보를 원하시면.
동적으로 컨트롤러 및 CSS 파일을로드해야하는 루트에서 해결 방법이 있습니다. 당신의 timeout
이 완료 될 때까지 기다리지 않고 또한 데이터를 반환하지 않습니다 defer.promise
때문이고
.when('/url', {
templateUrl: 'someview',
controller: 'somecontroller',
resolve: {
load: function (loadDependencies) {
loadDependencies.load(); // here i need to know get the result of what's inside $timeout of 'load'
}
}
})
본인의 예에서 볼 수 있듯이 약속을 반환합니다. 당신이 얻고있는 것은 3 초 후에 해결 될 보류중인 약속입니다. – cbass
약속이 해결 될 때까지 반품을 연기 할 수있는 방법이 있습니까? – emc
왜 그랬습니까? 그것의 목적은 무엇인가? – cbass