Using angular I want my form input to update the 'replied' section of a nested json file. When the form submit button is clicked I want the function add() to push the users first name, last name, and message to replied section of the json file.
app.js:
$http.get('/app/javascripts/data.json').success(function(responsetext){
angular.fromJson(responsetext);
$scope.activity = responsetext.activity;
$scope.replied = responsetext.replied;
//console.log(responsetext.replied);
$scope.admin = responsetext.admin;
//console.log($scope.admin);
$scope.menu = responsetext.menu;
//console.log($scope.menu);
//console.log($scope.replied);
})
.error(function (responsetext) {
console.log("Error retrieving user data.");
});
$scope.showAdd = function(ev) {
$mdDialog.show({
controller: DialogController,
template: '
<md-dialog aria-label="Mango (Fruit)">
<md-content class="md-padding">
<form name="userForm">
<div layout layout-sm="column">
<md-input-container flex>
<label>Contact Name</label>
<input ng-model="user.contactName">
</md-input-container></div>
<md-input-container flex>
<label>Message</label>
<textarea ng-model="user.message" columns="1" md-maxlength="150"> </textarea>
</md-input-container>
</form>
</md-content>
<div class="md-actions" layout="row">
<span flex></span>
<md-button ng-click="answer(\'not useful\');"> Cancel </md-button>
<md-button ng-sumbit="add();" class="md-primary"> Send </md-button>
</div></md-dialog>',
targetEvent: ev,
})
data.json:
"replied":[
{
"what":"Did You Study?",
"who":"Keith David",
"when":"6:45pm",
"notes":"I'm on my way."
},
{
"what":"Movies Saturday Night?",
"who":"Kim, Scott, Jennifer",
"when":"4:31pm",
"notes":"Wish I could go, but I'm out of town this weekend"
},
{
"what":"Studying Abroad Next Semester",
"who":"Sandra Adams",
"when":"12:22pm",
"notes":"You should do shopping on Champs-Élysées!"
},
{
"what":"Birthday Gift",
"who":"Trevor Hansen",
"when":"5:00pm",
"notes":"Let's give her a surprise party at her favorite resturant!"
},
{
"what":"Grocery Shopping",
"who":"Lamman Davis",
"when":"4:35pm",
"notes":"Don't forget the salas, cheddar cheese, and we are out of almond milk. Thanks"
}
],