首页 > 解决方案 > 如何将来自http调用的简单csv数据转换为角度字符串?

问题描述

我有一个应用程序,我想在其中显示通过 http 请求创建的数据。在我要显示的视图中:2020 年格陵兰的人口为 56081 人。

此查询http://betabank.stat.gl/sq/74c8dac5-97a0-4457-ace9-057de3e1308f返回一个简单的 CSV 文件:

“”“2020”“”56081

我在浏览器中工作正常,但如何以角度导入打字稿中的内容。请参阅下面的我的 html 和打字稿。

我曾尝试在 html 中使用 embed、iframe 和其他解决方案,但无法正常工作。如何在角度应用程序中打开其他网站

请帮忙

我的html:

<div>
  <h2>Test simpel http import</h2>
  <p>{{outputstring}} </p>
</div>

我的打字稿:

import { Component} from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})

export class AppComponent {
  inputstring: string;
  inputnumber: string;
  outputstring: string;

  ngOnInit() {
    this.inputstring = "The population in Greenland in 2020 are {{}} persons.";
    this.inputnumber = "56081";

   // I need to get inputnumber from this http-call (transformed)
   // http://betabank.stat.gl/sq/74c8dac5-97a0-4457-ace9-057de3e1308f

    this.outputstring = this.inputstring.replace("{{}}", this.inputnumber);

  } 
}

标签: angulartypescriptcsvhttp

解决方案


推荐阅读