我正在尝试使用接口从 API 获取数据。Bellow是我的临时界面
export interface ITemp {
id: number,
name: string,
age: number
}
下面是我的 HTTP 服务,其中有一个 fn getHomedetails,它调用了一个 API。
import {Injectable} from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { ITemp } from "../interfaces/temp";
import { Observable } from "rxjs/Observable";
import 'rxjs/Rx';
@Injectable()
export class HttpService{
http:any;
baseUrl: String;
constructor(http:HttpClient){
this.http = http;
this.baseUrl = 'some_url';
}
getHomeDetails(): Observable<ITemp> {
return this.http.get<ITemp>(this.baseUrl); //problem is here
//when mouse is pointed on get<ITemp> it shows "Untyped function calls may not accept type arguments"
}
}
未定义接口。我不知道我做错了什么。上面的语法是 Angular 4.3X 语法。我使用的编辑器是 sublime 和 visual studio。