这是我的 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)
}
})
这是一个带有关联徽章的选项卡:
<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>
这是物种服务:
.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;
当用户在选择输入中选择选项时,我使用 speciesService 从服务器请求数据。然后,我想根据返回对象的计数更新徽章。
我不确定如何将此物种服务连接到另一个模板中的徽章女巫。
最佳答案
假装我没有注意到您正在使用 jQuery 并从 Controller 内部访问 DOM:
.controller('FilterCtrl', function($scope, $http, tagsService, speciesService) {
$scope.speciesData = speciesService.data;
...
<ion-tab ... badge="{{speciesData.species.length}}"
关于javascript - Angular - 更新模板中的徽章编号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25823613/