编译代码时遇到此错误:
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
@Injectable()
export class TaskService {
constructor(private http: HttpClient) {
}
getTasks() {
return this.http.get('/api/tasks');
}
}
src / app / tasks / task.service.ts(4,1)中的错误:错误TS1238:当作为表达式调用时,无法解析类装饰器的签名。
我不确定它出错的地方...... 4,1是Injectable之前的@符号。
答案 0 :(得分:1)
尝试添加return
类型getTasks(): Observable<any>
。
你正确地注射了HttpClientModule
吗?
import { HttpClientModule } from '@angular/common/http';
@NgModule({
imports: [
BrowserModule,
// Include it under 'imports' in your application module
// after BrowserModule.
HttpClientModule,
],
})