简体   繁体   中英

How to take data from a csv file? Angular 2

I'm new to Angular 2.

There are many questions related taking data from a CSV file. I want to implement this kind of feature using Angular 2. How should I proceed?

It's like: I want to create a new CSV file with some URLs. And then create a service for it and render data from URLs provided in the CSV file. 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 .

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

In an easy case you can just have a div and set the content, after you extracted your URL:

<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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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