3

I am developing the front end of an application in AngularJS. Input is given in a search box, on clicking the search button, I have to save the data in a text file. (The input will be a string). How do I do this?

Also, after this operation, I have to view the output stored in a text file in the html. How do I do this?

10
  • 1
    What have you tried so far? share some code... or are you expecting code from scratch? Commented Oct 1, 2015 at 19:20
  • 1
    I just googled very "angularjs writing to file", wasn't that hard to find out: stackoverflow.com/questions/28536265/… Commented Oct 1, 2015 at 19:20
  • What you mean by saying "save"? Do you want to write in file system or in memory? Commented Oct 1, 2015 at 19:29
  • 1
    @akashrajkn write to any file would be a serious security hole. Commented Oct 1, 2015 at 19:51
  • 2
    Why do you need to save to a text file? ... How about a "data storage" like a database? ... Do the end user need to access the text file from somewhere else? Commented Oct 8, 2015 at 6:09

3 Answers 3

2

Quite often the saved data is not for the end user but the app.

A text file seems often as a simple and quick way (which is kind of isn't when we talk about web apps and client side access).

At this link, Client-Side Storage, you find a few "local storage solution" and their pros/cons, which you can compare with server based databases, to find the best way for your app.

And as its title says, the benefit of client side storage is access to it without internet connection.

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

Comments

1

You can use the full power of the File System API only if you can get the user to select the file you need to write to. You can use cookies in your code if that is not your case.

The saveData function can save whatever the string you need in a cookie. The file will be there even after you close the browser (set for 30 days in my example).

The loadData function returns the data you saved in a previous session.

Use $cookies provider in Angular if you use it. It sums the things up in a nicer way.

You will see that cookies can do much more things including saving multiple data sets in multiple files if you explore bit more by googling about it.

function saveData(searchQuery) {

    var d = new Date();
    d.setTime(d.getTime() + (30*24*60*60*1000));
    var expires = "expires="+d.toUTCString();

    document.cookie = "mySearch=" + searchQuery + "; expires=" + expires;

};

   function loadData() {
       return document.cookie;
   }

Comments

0

Look at this link : js-xlsx. Another way is to use the angular.toJson method, save into a json file and access it as needed

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.