I'm feeling a bit disoriented regarding my current issue. The scenario involves two views and a controller that interact with a service. The first view consists of a table list containing items loaded from a WebAPI. The service sends requests to the server and handles ordering. Additionally, another service is used to transfer the selected row item to the other controller. Below is the code snippet:
View 1:
//view1.html
<table class="table table-bordered table-hover">
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in namelist" ng-click="open(this.item)">
<td>{{ item.fname }}</td>
<td>{{ item.lname }}</td>
</tr>
</tbody>
</table>
Controller 1:
//FirstCtrl
$scope.namelist = reqService.names.query();
$scope.open = function (item) {
$scope.selectedItem = item;
modalService.openDialog($scope.namelist, $scope.selectedItem);
}
HTTP Service:
//Service for HTTP Requests
testApp.factory('reqService', ['$resource', 'baseUrl', function ($resource, baseUrl) {
return {
names: $resource(baseUrl + '/api/name/:Id', {
Id: '@Id'
}, {
'update': {
method: 'PUT'
}
})
}
}]);
Modal Dialog Service:
//Modal dialog service
testApp.factory('modalService', ['$modal', function ($modal) {
return {
openDialog: function (namelist, selectedItem) {
return $modal.open({
templateUrl: 'views/view2.html',
controller: 'SecondCtrl',
resolve: {
namedList: function () {
return namelist;
},
selected: function () {
return selectedItem;
}
}
});
}
}
}]);
Controller 2:
testApp.controller('SecondCtrl', ['$scope', '$modalInstance', 'namedList', 'selected', 'reqService', '$http'..., function (...){
/*copy of the original items*/
$scope.copyItem = angular.copy(selected);
$scope.cancel = function () {
$scope.selected = angular.copy($scope.copyItem);
$modalInstance.dismiss('cancel');
}
$scope.reset = function () {
$scope.selected = angular.copy($scope.copyItem);
selected = angular.copy($scope.copyItem); //doesn't work
}
}
My query is how can I refresh the tablelist? Upon clicking the reset button, it only resets the form in the modal window while the changes persist in the table list?! I'm unable to reset the "selected" variable in the resolve.