$http ではなく xhr を使用するサードパーティのライブラリを使用する場合、サービスで promise を使用する正しい方法は何ですか?
getSomething: function(user, repo) {
var deferred = $q.defer();
client.doSomething().promise().then(function(result) {
$rootScope.$apply(function() {
deferred.resolve(result);
});
}, function(err) {
$rootScope.$apply(function() {
deferred.reject(err);
});
});
return deferred.promise;
}
$rootScope をそのように使用するのは見苦しく、Angular らしくないように見えますが、スコープをパラメーターとして渡す場合も同様です。これを行うより良い方法はありますか?