1

how can I read a file using Angular 2 without using a html view. for examples up to now they have provided an example like.

How to make FileReader work with Angular2

using

 <input type="file" (change)="changeListener($event)"> 

selecting a file using an input.

I want give my constant path for it without selecting the file from the view how can i do it ?

1 Answer 1

3

For Security reasons, the browsers do not allow access to absolute path & file systems directly to Javascript. You can only read files using tags like you said

<input type="file" (change)="changeListener($event)">

And FileReader Api is just a more convinient way to do this. So basically speaking you can't do what you want, at least without some really hacky tricks :)

Sign up to request clarification or add additional context in comments.

1 Comment

thank you need to find and alternative way: also i can create a json file and import it into my component then I can use its data.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.