As a newcomer to both Ionic and Angularjs, I am currently in the process of developing a simple Ionic app. The main functionality involves displaying a list of classes (sessions), allowing users to book or cancel a class by clicking on an icon, and updating the card to show the number of remaining places in each session on the day.
Although I have successfully implemented the code to add and remove a person from a class, I am facing difficulty in updating the template view from within the controller. Here is an example of my controller code:
// Check Person into session.
$scope.addCheckIn = function(schedule){
var promise = sessionDataService.checkinSession(schedule.sessionID);
promise.then(function(data){
// Update (refresh) Schedule Details
// Unsure of what to put here??
});
};
I have tried various approaches such as refreshing the $state, calling doRefresh, and even re-populating the cards using the original controller methods. However, the view does not update unless I manually switch between states on the screen.
//$state.go('app.schedules', {}, {reload: true});
//$scope.doRefresh();
//getScheduleData(formatDate(selectedDate), formatDate(selectedDate), 'true');
Additionally, I have explored $scope.apply and $scope.timeout, but I am unsure if these are leading me towards the correct solution.
What is the recommended way to update the view after making changes? Should it be done after the promise.then in the controller, or should I call a service to handle the update?
Any advice on the best approach for resolving this issue would be greatly appreciated. Thank you for your help.