I have an ng-repeat set up showing a list of groups on a page. I would like to click on one of those groups and have the data specific to the clicked group show up on a 'details' page i have already created. I have tried several methods to do this and the farthest I have gotten is not very impressive. Any help would be appreciated.
index.html:
<div class="containerList">
<div class="row">
<div class="col-md-4" ng-repeat="group in data.groups | filter: filterObject | filter: search">
<div class="panel panel-default">
<div class="panel-heading">
<h5 class="panel-title"><a href="#groupDetail" ng-click="open(group)">{{group.name}}</a></h5>
</div>
<div class="panel-body">
<div class="btn-group">
<button type="button" class="btn btn-default" >{{group.products}}</button>
</div>
</div>
</div>
</div>
</div>
</div>
groupCtrl:
creativeBillingApp.controller('GroupCtrl', ['$scope', 'groupsService', function( $scope, groupsService, $firebase ) {
$scope.newGroup = {
name: '',
status: ''
};
$scope.data = {};
$scope.data.groups = groupsService.getGroups();
$scope.groups = groupsService;
$scope.addGroup = function(newGroup) {
groupsService.addGroup(newGroup);
$scope.newGroup = {
name: '',
status: ''
};
};
$scope.updateGroup = function (id) {
groupsService.updateGroup(id);
};
$scope.removeGroup = function(id) {
groupsService.removeGroup(id);
};
$stateProvider
.state('groupdetail', {
url : '/groupdetail/:id',
controller : 'GroupCtrl',
templateUrl : 'groupDetails.html'
})
$scope.groupId = $stateParams.id; // You will get id, and you can extract data using this id
}])
.factory('groupsService', ['$firebase', 'FIREBASE_URI',
function ($firebase, FIREBASE_URI) {
var ref = new Firebase(FIREBASE_URI + '/groups');
var groups = $firebase(ref).$asArray();
var getGroups = function(){
return groups;
};
var addGroup = function (newGroup) {
console.log(newGroup)
groups.$add(newGroup);
};
var updateGroup = function (id){
groups.$save(id);
};
var removeGroup = function (id) {
groups.$remove(id);
};
return {
getGroups: getGroups,
addGroup: addGroup,
updateGroup: updateGroup,
removeGroup: removeGroup,
}
}]);
groupDetail.html:
<div class="panel panel-default">
<div class="panel-heading">
<h5 class="panel-title">
{{group.name}}
</h5>
</div>
</div>