【问题标题】:Angular - update badge number in templateAngular - 更新模板中的徽章编号
【发布时间】: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


【解决方案1】:

假装我没有注意到您正在使用 jQuery 并从控制器内部访问 DOM:

.controller('FilterCtrl', function($scope, $http, tagsService, speciesService) {
    $scope.speciesData = speciesService.data;
    ...

<ion-tab ... badge="{{speciesData.species.length}}"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多