Refresh ng-repeat rows when new data is added to source using parse.com
-
I have this AngularJS controller wich fetches data from a class I have created on parse.com app.controller('dataCtrl', function($scope) { var MarketingData = Parse.Object.extend('MarketingData'); var query = new Parse.Query(MarketingData); 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') } }); }); } }); }); Together with this HTML <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> How can I bind a button to refresh the rows with new data (new rows)? I'm fairly new to both parse.com and AngularJS. Thank's
-
Answer:
You should put your code to get data inside a function, then call that function when you press on the refresh button. I'd write it like it : app.controller('dataCtrl', function($scope) { function getData() { var MarketingData = Parse.Object.extend('MarketingData'); var query = new Parse.Query(MarketingData); query.find({ success: function(results) { $scope.$apply(function() { $scope.resultData = results.map(....); }); }); }); }; getData(); //Get data on launch $scope.refreshData = function() { getData(); } }); In the HTML, just add : <button value="Refresh" ng-click="getData()"></button>
David at Stack Overflow Visit the source
Related Q & A:
- How to skip columns empty in CSV file when importing into MySQL table using LOAD DATA INFILE?Best solution by Stack Overflow
- How to add a new table to a data source?Best solution by technet.microsoft.com
- How to open a new ng-view inside ng-view?Best solution by Stack Overflow
- How to use ng-switch in ng-repeat?Best solution by Stack Overflow
- When I click on the YIM icon at Yahoo.com, I am sent to the download page, instead of YIM already loaded. Why?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.