[英]TypeScript and Angular Services
When writing services in TypeScript
for AngularJS
do you define a model for the request and the response? 在用TypeScript
for AngularJS
编写服务时,您是否为请求和响应定义模型?
So for example, given the following service call into a RESTFul endpoint from the service: 因此,例如,给定以下服务从该服务到RESTFul端点的调用:
module Application {
export module Services {
export class MyService {
public static $inject = ["$http"];
constructor(private $http: ng.IHttpService) {
}
getSomeData = (model: Models.RequestModel): ng.IPromise<Models.ResponseModel> => {
this.$http.post("url", model).then((response: ng.IHttpPromiseCallbackArg<Models.ResponseModel>) => {
return response.data;
});
}
}
}
}
So basically I am sending the RequestModel
and receiving back the ResponseModel
所以基本上我是在发送RequestModel
并接收回ResponseModel
Would that be the proper use/syntax? 那是正确的用法/语法吗?
So basically I am sending the RequestModel and receiving back the ResponseModel, Would that be the proper use/syntax? 所以基本上我是在发送RequestModel并接收回ResponseModel的,这是否是正确的用法/语法?
Yes. 是。 Request in, promise to Response out. 要求输入,答应响应。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.