如何使用ng-repeat将表数据显示到表中?

时间:2016-04-18 04:37:04

标签: angularjs

这是来自Api的我的回复数据。通过使用ng-repeat如何将数据显示到表中。 response包含数组数组。 itemsList是我的响应数据名称。

[Array[1], Array[0]]
0:Array[1]
0:Resource
$$hashKey:"object:22"
__v:0
_id:"5712254566dfa48c16d481d5"
bprice:100
createdat:"2016-04-16T11:43:01.471
modifiedat:"2016-04-16T11:43:01.471Z"
notifyqty:10
prodcutcategory:"sport shoe"
productcode:"439971"
productname:"zxcvb"
productnote:"zdc"
productqty:60
size:8
sprice:200
__proto__:Object
$$hashKey:
"object:20"
$promise:Promise
$resolved:true
length:1
__proto__:Array[0]
1:Array[1]
0:Resource
$$hashKey:"object:26"
__v:0
_id:"5712257366dfa48c16d481d6"
bprice:100
createdat:
"2016-04-16T11:43:47.462Z"
modifiedat:"2016-04-16T11:43:47.463Z"
notifyqty:10
prodcutcategory:"Sandal"
productcode:"590893"
productname:"bata"
productnote:"rough"
productqty:50
size:7
sprice:150
__proto__:
Object
$$hashKey:"object:24"
$promise:Promise
$resolved:true
length:1
__proto__:Array[0]
length:2
__proto__:Array[0]

这是我在html中的表重复

 <tr ng-repeat="list in itemsList">
                          <td>{{$index+1}}</td>
                          <td>{{list.productname}}</td>
                          <td>{{list.productquantity}}</td>
                          <td>{{list.sprice}}</td>
                          <td>{{list.sprice*list.productquantity}}</td>
                         <td><button type="button" class="fa fa-trash btn   btn-danger" ng-click="remove($index,list._id)"></button></td>

                      </tr>

当我点击按钮时,它会从输入中将条形码作为ng-model发送 我收到了服务的回复。 最后每次条形码的新条目

时,响应都会进入itemsList
 $scope.getOrder=function(barcode){
    $scope.orderlist=GetproductBarcodeService.getAllCartofproducts(barcode);
    $scope.itemsList.push($scope.orderlist)
    console.log($scope.itemsList)
 }

请告诉我如何重复此事。

1 个答案:

答案 0 :(得分:0)

试试这个控制器代码可能会对你有帮助

//Create itemsList array 
    $scope.itemsList = [];

$scope.getOrder = function(){
// Use example result 
        $scope.orderlist = { id : '312312',data : 'wel come'};
        console.log($scope.orderlist);
        $scope.itemsList.push($scope.orderlist);
        console.log($scope.itemsList);
    }

尝试此操作并查看控制台注销