This is my controller:
.controller('FilterCtrl', function($scope, $http, tagsService, speciesService) {
$scope.tags = tagsService.getTags();
$scope.fileNameChanged = function(event) {
q = []
_.each($(event).find(":selected"), function(el) {
if ( $(el).text().trim() !== "" ) {
q.push($(el).text().trim())
}
})
q = q.join('&')
s = speciesService.getList(q)
}
})
This is a tab with a badge associated to it:
<ion-tab title="List" icon="icon ion-navicon-round" href="#/tab/list" badge="0" badge-style="badge-assertive">
<ion-nav-view name="tab-list"></ion-nav-view>
</ion-tab>
Here is the speciesService:
.factory('speciesService', function($http) {
var speciesService = {};
speciesService.data = {};
speciesService.getList = function (q) {
$http.get("http://localhost:8080/api/v1/species/?format=json&tags=" + q, {})
.success(function(data, status, headers, config) {
speciesService.data.species = data;
console.log(speciesService.data.species.objects.length);
})
// .error(function(data, status, headers, config) {
// console.log(status)
// tags = [];
// });
return speciesService.data;
}
return speciesService;
When the user chooses options in a select input, I am requesting data from the server with speciesService. Then after that I want to update the badge based on the count I have for the returned objects.
Im not sure how you connect this speciesService to the badge witch is in another template.
Pretending I didn't notice the fact that you are using jQuery and accessing the DOM from inside your controller:
.controller('FilterCtrl', function($scope, $http, tagsService, speciesService) {
$scope.speciesData = speciesService.data;
...
<ion-tab ... badge="{{speciesData.species.length}}"