2015-01-21 41 views
-1

如何將響應數據動態綁定到ng-repeat內生成的html?如何在ng-repeat內部綁定html?

目前,只有socialCount被綁定到所有的li。

這裏是我的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 =功能(類別){

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

問題不清楚,inbox.categories究竟是什麼?你究竟想要綁定什麼? – yeswanth 2015-01-21 08:18:31

+0

這段html需要綁定。正如你所看到的,我只在每個循環傳遞中使用了socialCount。我需要循環中的每個傳球的forumsCount,updatesCount等; – shashank 2015-01-21 08:20:33

+0

你不必擔心類別,它工作正常,只是計數不受限制。 – shashank 2015-01-21 08:21:59

回答

0

找到答案,只需要做到這一點。

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