2016-03-15 29 views
3

我通過顯示一個表NG-重複角1.5不更新NG-重複

 <div ng-app="spApp"> 
<div ng-controller="spListCtrl as MyList"> 
<table width="100%" cellpadding="10" cellspacing="2"> 
    <thead> 

     <th>First Name</th> 
     <th>Last Name</th> 
     <th>Email</th> 
     <th>CellPhone</th> 
     <th>Update</th> 
    </thead> 
     <tbody> 
     <tr ng-repeat="item in MyList.Contacts track by $index"> 

      <td class="align-center"><input type="text" ng-model="MyList.Contacts[$index].FirstName"> </input></td> 
      <td class="align-center">{{MyList.Contacts[$index].Title}}</td> 
      <td class="align-center">{{MyList.Contacts[$index].Email}}</td> 
      <td class="align-center">{{MyList.Contacts[$index].CellPhone}}</td> 
      <td class="align-center"><button ng-click="ShowNewForm(MyList.Contacts[$index])">Изменить</button></td> 
     </tr> 
    </tbody> 
</table> 

加載通過該服務,並數據分配爲正常,但不顯示。什麼沒有嘗試過,告訴我我做錯了什麼。

同時使用 controllerAs模式

回答

1

,做綁定數據綁定變量this(控制器功能方面),這樣你就可以在HTML中使用它訪問它們的別名MyList(這是控制器功能的情況下)。

代碼

spApp.controller('spListCtrl', function spListCtrl(dataService){ 
    var self = this 
    var promiseObj=dataService.getContacts(); 
    promiseObj.then(function(value) { 
     self.Contacts=value.data; 
    }); 
}); 

而且裏面ng-repeat使用item有約束力的工作。

<tr ng-repeat="item in MyList.Contacts track by $index"> 

     <td class="align-center"><input type="text" ng-model="item.FirstName"> </input></td> 
     <td class="align-center">{{item.Title}}</td> 
     <td class="align-center">{{item.Email}}</td> 
     <td class="align-center">{{item.CellPhone}}</td> 
     <td class="align-center"><button ng-click="ShowNewForm(item)">Изменить</button></td> 
    </tr> 
+1

此外,我們可以使用{{item.Title}}而不是MyList.Contacts [$ index] .Title。我們不能嗎?其他屬性也一樣。 –

+0

@NagaSandeep正確..我錯過了..感謝您的支持.. –

+0

使用controllerAs語法時,無需注入'$ scope'。你也需要訪問承諾結果的'.data'屬性。例如'self.Contacts = value.data; '。 – Lex