【问题标题】:Cannot find name 'Http' in Angular 10在 Angular 10 中找不到名称“Http”
【发布时间】:2021-03-10 22:38:02
【问题描述】:

我想在我的 Angular 组件中呈现外部输入模板。但是没有找到“http”。我还在项目中安装了@types/node,但这并没有解决依赖关系。

我正在尝试通过此代码进行设置:

<div style="height: 300px;">
    <div [innerHTML]="stepTemplate"></div>
</div>

setView() {
   const temp =  this.inputModel.templateUrl;
   this.stepTemplate = this.http.get(temp).map((html: any) => this.stepTemplate = html);
}

import * as Http from 'http';    
export class JourneyLineComponent implements OnInit, AfterViewInit {
    
        .....
        http: Http;
    }

【问题讨论】:

    标签: angular typescript http templates angular10


    【解决方案1】:

    我相信这就是你想要的导入

    从 '@angular/common/http' 导入 { HttpClient };

    Angular 从几个版本的 Http 切换到 HttpClient

    另外,你想将它注入到你的构造函数中

    构造函数(私有 http: HttpClient){}

    【讨论】:

      猜你喜欢
      • 2020-11-18
      • 2021-02-27
      • 1970-01-01
      • 2016-01-24
      • 2022-01-10
      • 1970-01-01
      • 1970-01-01
      • 2017-09-14
      相关资源
      最近更新 更多