新手问题。下面的代码有什么问题?无法说出get属性TypeError:无法读取未定义的属性'get'
var http: HttpClient;
const req = http.get<any>(url)
.subscribe(
res => {
答案 0 :(得分:3)
您可以这样做
category_id
答案 1 :(得分:0)
首先在构造函数中注入HttpClient,然后您可以像这样使用它。
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
@Injectable()
export abstract class DataService {
constructor(private http: HttpClient) {}
public get<T>(url: string, params?: any): Observable<T> {
return this.http.get<T>(url, {headers: headers, params: params});
}
}
或
const req =this.http.get<any>(url)
.subscribe(
res => {