Angular TS错误@Injectable标记角度为5
我在编译代码时遇到以下错误:Angular TS错误@Injectable标记角度为5,angular,typescript,angular5,Angular,Typescript,Angular5,我在编译代码时遇到以下错误: 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
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.ts4中出错,1:错误TS1238:作为表达式调用时无法解析类装饰器的签名
我不确定哪里出了问题。。。4,1是可注入之前的@符号。尝试添加返回类型getTasks:Observable。
您是否正确注入了HttpClientModule
import { HttpClientModule } from '@angular/common/http';
@NgModule({
imports: [
BrowserModule,
// Include it under 'imports' in your application module
// after BrowserModule.
HttpClientModule,
],
})
工作得很有魅力。错误是由没有返回类型引起的,另一个基本错误是由没有正确注入HttpClientModule引起的。都是固定的。现在正在学习angular Cli教程,该教程位于angular 4上,因此其中一些内容有所不同/不推荐。谢谢返回类型不应导致此错误。但是,如果函数实际返回某些内容,则最好定义返回类型。Angular 5比以前更严格: