繁体   English   中英

无法在 Angular 中发送带有“http”的请求

[英]Cannot send a request with “http” in Angular

我正在尝试向 WebApi 发送请求,但“http”字样出现错误,提示“'ProductComponent' 类型上不存在属性 'http'”

这是我的代码

import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from "@angular/router";
import { HttpClient } from "@angular/common/http";
import { Observable } from 'rxjs';

interface Product {
  description: string;
  courseListIcon: string;
  iconUrl: string;
  longDescription: string;
  url: string;
}

@Component({
  selector: 'app-product',
  templateUrl: './product.component.html',
  styleUrls: ['./product.component.css']
})
export class ProductComponent implements OnInit {

  public urlParameter: string;
  public product: Object; //Product

  constructor(private route: ActivatedRoute) { }

  ngOnInit() {
    this.urlParameter = this.route.snapshot.paramMap.get("urun");
    console.log(this.urlParameter);

    this.product = this.http.get<Product>("url");      // this line gives the error ***********
  }

}

我在这里错过了进口吗? 请帮忙...

您需要将HTTPClient注入您的组件 class。

constructor(private route: ActivatedRoute, private: http: HTTPClient) { 

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM