【发布时间】:2014-09-13 23:49:48
【问题描述】:
这是我的控制器:
.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 从服务器请求数据。然后,我想根据我对返回对象的计数来更新徽章。
我不确定你是如何将这个 speciesService 连接到另一个模板中的徽章女巫的。
【问题讨论】:
-
需要将
badge=""绑定到绑定到speciesService.data或被事件广播更新的范围变量
标签: javascript html angularjs angularjs-scope ionic-framework