简体   繁体   English

如何从csv文件中获取数据? 角度2

[英]How to take data from a csv file? Angular 2

I'm new to Angular 2. 我是Angular 2的新手。

There are many questions related taking data from a CSV file. 从CSV文件获取数据有很多问题。 I want to implement this kind of feature using Angular 2. How should I proceed? 我想使用Angular 2实现这种功能。我应该如何进行?

It's like: I want to create a new CSV file with some URLs. 就像:我想用一些URL创建一个新的CSV文件。 And then create a service for it and render data from URLs provided in the CSV file. 然后为其创建服务,并从CSV文件中提供的URL呈现数据。 But I'm not sure will it work? 但我不确定是否会奏效? It would be great if anyone can suggest a better idea to implement this kind of feature. 如果有人可以提出一个更好的想法来实现这种功能,那将是很好的。 :) :)

Depending on your environment, you could just download the file via Angular 2's HTTP Client or if you're using NodeJs for example, you can read the file from your hdd . 根据您的环境,您可以只通过Angular 2的HTTP客户端下载文件,或者例如,如果您使用的是NodeJ,则可以从hdd中读取文件

Processing shouldn't be a problem, as you can go through the file line by line and split the line according to the used separator to get each field. 处理应该没有问题,因为您可以逐行浏览文件,并根据使用的分隔符分割行以获取每个字段。

The next step depends on what you mean by 下一步取决于您的意思

render data from URLs 从URL呈现数据

In an easy case you can just have a div and set the content, after you extracted your URL: 在简单的情况下,您可以在提取URL后仅具有一个div并设置内容:

<div [innerHtml]="myUrlStuff">
</div>
....

export public class MyClass {

    public myUrlStuff:string;
    @Input() url: string;

    constructor(http: Http) {
        this.myUrlStuff = '';
        http.get(yourUrl).map((res) => this.myUrlStuff = res);
    }
}

You probably need some adjustments, this is just an example, which probably don't directy work. 您可能需要进行一些调整,这只是一个示例,可能没有直接作用。

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

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