如何在ng-repeat中绑定html?

时间:2015-01-21 08:15:03

标签: javascript angularjs angularjs-scope angularjs-ng-repeat

如何将响应数据动态绑定到ng-repeat内生成的html?

目前,只有socialCount受到所有人的约束。

这是我的HTML:

<li ng-repeat="category in inbox.categories track by $index">
                                <a href="#">
                                    <div class="left-row" ng-click="inbox.showView(category)" target="_self">
                                        <div class="leftcolumn1"><span class="glyphicon glyphicon-user"></span></div>
                                        <div class="leftcolumn2">{{category}}</div>
                                        <div class="leftcolumn3 email-time" ng-bind="inbox.messageCounts.socialCount"></div>
                                    </div>
                                </a>
                            </li>

我从服务器得到的响应是:

{"socialCount":431,"promotionsCount":17843,"updatesCount":26997,"forumsCount":1780}

js功能:

Inbox.prototype.getMessageCounts = function(categories){

$http.get(
this.messageCountUrl + this.userGuid).success(function(data){
    this.messageCounts=data;
}.bind(this));

1 个答案:

答案 0 :(得分:0)

找到答案,只需这样做。

<div class="leftcolumn3 email-time" ng-bind="inbox.messageCounts.{{category|lowercase}}Count"></div>