In my controller.js
file for AngularJS, I have the following code snippet:
app.controller('MetaDetailGroupList', ['$scope', '$http', function($scope, $http) {
$http.get(Routing.generate('meta-detail-group-list')).success(function(data) {
$scope.MetaDetailGroup = data;
$scope.orderProp = 'name';
$scope.currPage = 0;
$scope.pageSize = 10;
$scope.totalMetaDetailGroup = function() {
return Math.ceil($scope.MetaDetailGroup.entities.length / $scope.pageSize);
};
}).error(function(data, status, headers, config) {
$scope.MetaDetailGroup.message = "An error occurred while processing the data, please try again.";
});
}]);
This function is used to create a list of items and it functions as expected. Some of these items have a parent >> children
relationship, requiring another call to the same function but with an ID passed as an optional parameter. The only change necessary is in this line:
From: $http.get(Routing.generate('meta-detail-group-list')).success(function(data)
To: $http.get(Routing.generate('meta-detail-group-list' + '/'+id)).success(function(data)
Is there a way to achieve this without creating a separate function specifically for this purpose?