I have categories and subcategories.
A data structure similar to blog shows:
categories: {
-JF1RmYehtF3IoGN9xHG(categoryId): {
title: "Example",
subcategories: {
JF1RmYehtF3IoGN239GJ(subCategoryId): true
}
Now I got the data this way (for only one category): [controller]
$scope.findOneCategory = function (categoryId) {
angularFire(Categories.find(categoryId), $scope, 'category');
}
And category service
find: function(categoryId) {
return FireRef.categories().child('/'+categoryId);
},
It works well!
But now I need to get a list of subcategories in the category and associate it with the scope, and I don't know how ... I currently have this:
View:
<div ng-init="findSubCategories()">
<li class="list-group-item" ng-repeat="subCategory in subCategories">{{ subCategory.name }}</li>
Controller:
$scope.findSubCategories = function() {
angularFire(Categories.findSubCategories($routeParams.categoryId), $scope, 'subCategories');
}
And the service looks like this, I tried something, but it's wrong, and I have no idea what it should look like ... if anyone could help, I would be so happy!
findSubCategories: function(categoryId) {
var subCategoriesIdsList = FireRef.categories().child('/'+categoryId).child('subcategories');
subCategoriesIdsList.on("child_added", function(snap) {
FireRef.subcategories().child("/"+snap.name()).once("value", function(snap) {
console.log(snap.val());(i see the object in console but have no idea how to bind it now with the view...:(
});
});
},
Don't know how to associate this with angular view