2015-09-08 186 views
0

我有对象列表,如下所示,其中有对象嵌套在对象内。 我想使用ng-repeat显示信息,但它不起作用。ng-repeat用于显示对象列表中的嵌套对象

<div ng-repeat="x in customer"> 

         {{x.name}} 


       </div> 

AngularJs代码

var myapp=angular.module('myapp',[]); 
myapp.controller('MyController',['$scope',function($scope){ 
      $scope.val="this is test"; 
      $scope.customer= 
       [1:{ 
         name:{ 
         firstname:"", 
         lastName:"" 
        }, 
       address:{ 
         city:"city", 
         country:"country", 
         zipCode:65775 
      } 
      }, 
      //other customer data 
    ]; 

     }); 

为简单对象名单NG重复效果很好。我无法处理发生错误的复杂对象。

回答

1

务必:

<div ng-repeat="x in customer">Hi, {{x.name.firstname}} {{x.name.lastname}}!</div> 

如果你只是做

{{x.name}} 

你实际上不会输出任何东西,或者它会说[object Object]因为该值将[object Object]而不是任何性质的内物体。

1
<div ng-repeat="x in customer"> 
          <h3>{{x.name.firstname}} {{x.name.lastname}}<h3> 
          <p>{{x.address.city}} {{x.address.country}}</p> 
    </div> 
+0

这将输出另一个div与嵌套对象中的每个属性的信息。编辑:现在它是正确的。 – Chrillewoodz

+0

我已更新。 –