@Injectable 标签出现 TS 错误 Angular 5
TS error with @Injectable tag Angular 5
我在编译代码时 运行 遇到了这个错误:
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:当作为表达式调用时无法解析 class 装饰器的签名。
我不确定哪里出错了...4,1 是 Injectable 之前的 @ 符号。
尝试添加 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,
],
})
我在编译代码时 运行 遇到了这个错误:
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:当作为表达式调用时无法解析 class 装饰器的签名。
我不确定哪里出错了...4,1 是 Injectable 之前的 @ 符号。
尝试添加 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,
],
})