使用socket.io更新角度范围但我的视图没有更新

时间:2016-03-23 19:02:53

标签: javascript arrays angularjs

虽然以角度构建推送通知我遇到了一个问题,我的$ scope模型正在按预期更新,但我的视图在ng-repeat内部没有变化。

这就是我工厂的样子

var m = JSON.parse(message);
var n = JSON.parse(m.data.message);
var type = n.type;

$rootScope.$apply(function() {
      $rootScope.notifications[n.type].items.push(n);
      $rootScope.notifications[n.type].unread++;
});

我的ng-repeat代码在玉石模板中看起来像这样

ul.nav.navbar-nav
li.dropdown.dropdown-list(ng-repeat="(key,notification) in notifications" uib-dropdown="" ng-if="key != 'All'")
    a(uib-dropdown-toggle="" md-ink-ripple="")
        em.fa(ng-class="'fa-'+notification.icon")
        .label.label-danger(ng-if="notification.unread > 0") {{notification.unread}}
    ul.dropdown-menu(class="animated flipInX")
        li
            // START list group
            .list-group
                // list item
                a.list-group-item(ng-repeat="item in notification.items | limitTo:10" ng-if="item.read == 0")
                    .media-box
                        .pull-left
                            em.fa.fa-2x.text-info(ng-class='"fa-"+item.icon')
                        .media-box-body.clearfix
                            p.m0 {{item.title}}
                            p.m0.text-muted: small {{item.content}}
                a.list-group-item(href='' ng-if="notification.items.length == 0")
                    .media-box
                        .pull-left
                            em.fa(ng-class="'fa-'+notification.icon")
                        .media-box-body.clearfix
                            small No unread notifications.
                a.list-group-item(href='' ng-if="notification.items.length > 10")
                    small More notifications
                    .label.label-success.pull-right {{notification.items.length - 10}}

0 个答案:

没有答案