格式化显示来自angularjs的数据

格式化显示来自angularjs的数据,angularjs,Angularjs,API连接良好,显示数据,现在面临将数据格式化为表的问题。 使用ng repeat=“项目中的项目”, 如果在tr中使用,则仅显示1行,如果在tbody中使用,则其重复tbody HTML代码 <tbody ng-repeat="item in itemsc"> <tr > <th width="15%">Country</th

API连接良好,显示数据,现在面临将数据格式化为表的问题。 使用ng repeat=“项目中的项目”, 如果在tr中使用,则仅显示1行,如果在tbody中使用,则其重复tbody

HTML代码

                    <tbody ng-repeat="item in itemsc">
                    <tr >
                        <th width="15%">Country</th>
                        <td width="85%">{{item.name}}</td>
                    </tr>
                    <tr>
                        <th>Flag</th>
                        <td>
                            <img ng-src="/assets/images/f/{{item.iso2 | lowercase}}.png"  />
                        </td>
                    </tr>
                    <tr>
                        <th>Capital</th>
                        <td>{{item.capital}}</td>
                    </tr>
                    <tr>
                        <th>Region</th>
                        <td>{{item.region}}</td>
                    </tr>
                    <tr>
                        <th>Region</th>
                        <td>{{item.subRegion}}</td>
                    </tr>
                    <tr>
                        <th>GPS</th>
                        <td>Latitude: {{item.latitude}}  |  Longitude: {{item.longitude}}</td>
                    </tr>
                </tbody>

下面添加的代码片段:请查看角度代码,以及它在表中的实现方式。干杯


angular.module(“todoApp”,[])
.控制器(“主控制器”,功能($scope){
$scope.Products=[];
对于(变量i=0;i<3;i++)
{
变量应用={
我,
产品名称:“产品名称”+(i+1),
ProductCategory:'ProductCategory'+(i+1)
};
$scope.Products.push(应用程序);
}
});
高级工程师
{{$index+1}}
品名
{{product.ProductName}
产品类别
{{product.ProductCategory}

根据您的需求,简单的方法是更改传递到列表(itmes)的对象结构

例如

[{
“column1Value”:“国家”,
“column2Value”:“Value”
}, {
“column1Value”:“标志”,
“column2Value”:“Value”
}, {
“column1Value”:“资本”,
“column2Value”:“Value”
}, {
“column1Value”:“区域”,
“column2Value”:“Value”
}, {
“column1Value”:“GPS”,
“column2Value”:“Value”

}]
no,则仅重复tr,“键”是静态的。只有'Value'从angularjs函数中提取。将
ng repeat
放在
表中
> ------------------------------- 
|  Country |  Value              |
> -------------------------------
|  Flag |  Value              |
> -------------------------------
|  Catpital |  Value              |
> -------------------------------
|  Region |  Value              |
> -------------------------------
|  GPS |  Value              |
> -------------------------------