我有一个服务,包含$ http我的函数返回一个延迟对象.
我的界面:
export interface MyServiceScope {
get: ng.IPromise<{}>;
}
Run Code Online (Sandbox Code Playgroud)
我的课:
export class MyService implements MyServiceScope {
static $inject = ['$http', '$log'];
constructor(private $http: ng.IHttpService,
private $log: ng.ILogService,
private $q: ng.IQService) {
this.$http = $http;
this.$log = $log;
this.$q = $q;
}
get(): ng.IPromise<{}> {
var self = this;
var deferred = this.$q.defer();
this.$http.get('http://localhost:8000/tags').then(
function(response) {
deferred.resolve(response.data);
},
function(errors) {
self.$log.debug(errors);
deferred.reject(errors.data);
}
);
return deferred.promise;
}
}
Run Code Online (Sandbox Code Playgroud)
编译失败,出现以下错误:
myservice.ts(10,18): error TS2420: Class 'MyService' incorrectly implements interface 'MyServiceScope'.
Types of …Run Code Online (Sandbox Code Playgroud)