![](/img/trans.png)
[英]How can I encapsulate a $http.put into a function that does something and then returns a pass or fail promise?
[英]How can I create a Typescript interface for a function that returns an $http promise?
我正在使用此功能:
function httpGetQuestion(q) {
return $http({
url: '/api/Question/GetByUId/' + q.questionUId + '/fetch',
method: "GET"
})
}
還有這個:
test.getQuestion = function (q) {
getQuestion(q);
}
參數q的類型為IQuestion
如何創建代表這些功能的接口? 請注意,getQuestion函數不返回任何內容,但是httpGetQuestion返回一個Promise。
可能看起來像這樣:
module myModule
{
export interface IQuestion { ... }
export interface IMyService
{
httpGetQuestion(): ng.IHttpPromise<IQuestion>
getQuestion() : void
}
}
ng.IHttpPromise<T>
是代表$http
承諾的返回類型
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.