Adding data to an exsisting JSON file

Hi, i have just started learning Angular js. I find difficulty in adding the data to an existing JSON file.

This is my JSON file

{"response":[ {

This is my AngularJS code to push data

$scope.saveContact = function(contact){
$'/data/Cust_Dtls.json',contact).success(function(data, status, headers, config){

This is my HTML file

<ion-content  class="item-noborder base-bg" overflow-scroll="true" padding="true">
        <div class="row" >
            <div class="col-50 pane-top-padding-20" style="padding-left:10px"><a class="button button-icon button-positive ion-arrow-left-c" href="#/tab/contacts">&nbsp;Back to Contacts</a></div>
            <div class="col-50 pane-top-padding-20 text-right"><a class="button button-icon button-positive ion-checkmark text-right" href="#/tab/contacts" ng-click="saveContact(contact)">&nbsp;Save</a></div>

    <div  id="contact-div">

        <label class="item">
            <span class="input-label">First Name</span>
            <input type="text" placeholder="First Name" ng-model="contact.Cust_Fname">
        <label class="item">
            <span class="input-label">Last Name</span>
            <input type="text" placeholder="Last Name" ng-model="contact.Cust_Lname">
        <label class="item">
            <span class="input-label">Email</span>
            <input type="text" placeholder="Email" ng-model="contact.Cust_Email">
        <label class="item">
            <span class="input-label">Phone</span>
            <input type="text" placeholder="Phone" ng-model="contact.Cust_Mob">
        <label class="item">
            <span class="input-label">Date Of Birth</span>
            <input type="text" placeholder="DOB" ng-model="contact.Cust_Dob">



I am unable to save the data into the JSOn file. i will glad if anyone could help me.


You will have to use Cordova FIle API “writeExistingFile”

i just get $cordovaFile as undefined. Any help please.

any other way of writing data to a locally stored json file?

You need to install ng-cordova and use angular dependency injection to add $cordovaFile to your controller. And you only can use it on actual device, not browser.

i did install ng-cordova. and i did use the it on a mobile. but i don’t think it works. In a browser i am getting an error message saying that “undefined is not a function.” for $cordovaFile.writeFile.

When runninc on android you can do

ionic android run -l

and then type “c” to log all your console outputs from phone to command line, this way you can debug it running on acutal device

the command line is just blank. :frowning:

sorry instead of ionic android run -l you need to run ionic run android -l -c

are you on Unix or windows?

I am using windows… and i will try what you said