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":[ {
"Cust_Fname":"Jack",
"Cust_Lname":"Nicolson",
"Cust_Dob":"24/09/1992",
"Cust_Mob":"0987654321",
"Cust_Email":"abc@xyz.com
},
{
"Cust_Fname":"tom",
"Cust_Lname":"cruise",
"Cust_Dob":"19/01/1990",
"Cust_Mob":"1234567890",
"Cust_Email":"sss@gmail.com",
}
]
}

This is my AngularJS code to push data

$scope.saveContact = function(contact){
$http.post('/data/Cust_Dtls.json',contact).success(function(data, status, headers, config){
				console.log(data)});
			}

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>
        


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


    </div>
     

</ion-content>

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

Thanks
Venkatesh

You will have to use Cordova FIle API “writeExistingFile”

http://ngcordova.com/docs/plugins/file/

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