Angularjs return 从没有数据的函数向 return 发送虚拟承诺?
Angularjs returning dummy promise from function that have no data to return?
所以我有 clear/delete 一些数据的功能。
return 没有错误。 return 没有数据(时间函数到达 return 时不应该存在)。
需要承诺的代码:
SomeService.close().then(
function onSuccess() {
如何从 close() 中 return 一些有用的东西,然后可以使用?
//In SomeService
function close(){
delete that;
delete those;
delete etc;
return $q.defer().resolve().promise;
}
会给我以下错误:
$q.defer(...).resolve(...) is undefined
你的语法有点错误,试试:
function close(){
delete that;
delete those;
delete etc;
return $q.resolve();
}
您可以为此目的使用 $q.when。
function close(){
delete that;
delete those;
delete etc;
return $q.when();
}
来自docs:
Wraps an object that might be a value or a (3rd party) then-able
promise into a $q promise. This is useful when you are dealing with an
object that might or might not be a promise, or if the promise comes
from a source that can't be trusted.
所以我有 clear/delete 一些数据的功能。
return 没有错误。 return 没有数据(时间函数到达 return 时不应该存在)。
需要承诺的代码:
SomeService.close().then(
function onSuccess() {
如何从 close() 中 return 一些有用的东西,然后可以使用?
//In SomeService
function close(){
delete that;
delete those;
delete etc;
return $q.defer().resolve().promise;
}
会给我以下错误:
$q.defer(...).resolve(...) is undefined
你的语法有点错误,试试:
function close(){
delete that;
delete those;
delete etc;
return $q.resolve();
}
您可以为此目的使用 $q.when。
function close(){
delete that;
delete those;
delete etc;
return $q.when();
}
来自docs:
Wraps an object that might be a value or a (3rd party) then-able promise into a $q promise. This is useful when you are dealing with an object that might or might not be a promise, or if the promise comes from a source that can't be trusted.