nis*_*ave 1 javascript angularjs typescript angular4-httpclient angular5
我正在尝试使用接口从API获取数据.贝娄是我的临时界面
export interface ITemp {
id: number,
name: string,
age: number
}
Run Code Online (Sandbox Code Playgroud)
下面是我的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"
}
}
Run Code Online (Sandbox Code Playgroud)
接口未定义.我不知道我做错了什么.上面的语法是一个有角度的4.3X语法.我使用的编辑器是崇高的视觉工作室.
只是一个猜测,但我想这是因为你给你的班级http一类any:
更改http:any;到http: HttpClient
一个好的经验法则是不要使用,any除非你真的必须这样做.
| 归档时间: |
|
| 查看次数: |
3653 次 |
| 最近记录: |