I have this AngularJS
controller
app.controller('dataCtrl', function($scope) {
function getData() {
var myData = Parse.Object.extend('myData');
var query = new Parse.Query(myData);
query.find({
success: function(results) {
$scope.$apply(function() {
$scope.resultData = results.map(function(obj) {
return {
startDate: obj.get('StartDate'),
endDate: obj.get('EndDate'),
investment: obj.get('Investment'),
format: obj.get('Format'),
partner: obj.get('Partner'),
purpose: obj.get('Purpose')
}
});
});
}
});
}
getData();
$scope.refreshData = function() {
getData();
}
$scope.submit = function() { {
var myData = Parse.Object.extend('myData');
var formData = new myData();
formData.save({
StartDate: $scope.startDate,
EndDate: $scope.endDate,
Investment: parseInt($scope.investment),
Format: $scope.format,
Partner: $scope.partner,
Purpose: $scope.purpose
}, {
success: function(formData) {
console.log('Success');
}
})
}
});
Along with <form ng-submit="submit()">
and
<tr ng-repeat="x in resultData">
<td>{{x.startDate | date: 'yyyy-MM-dd'}}</td>
<td>{{x.endDate | date: 'yyyy-MM-dd'}}</td>
<td>{{x.investment}}</td>
<td>{{x.format}}</td>
<td>{{x.partner}}</td>
<td>{{x.purpose}}</td>
</tr>
I can successfully reload new data manually with a button calling the refreshData()
function. However I would like the view to update the ng-repeat
with the newly created row on a successful form submission. How can I do this?