通过循环数组显示ng-repeat中的值

时间:2017-04-08 20:14:24

标签: javascript html angularjs

我编写了一个代码来传递输入值并将其推送到数组中。然后我尝试使用ng-repeat来显示表中列表的值。但是我无法显示值数组。我无法在dispList中显示我的代码。

请告诉我如何在dispList中显示数组对象。

1 个答案:

答案 0 :(得分:0)

由于我缺少你的代码片段,我想我只想创建一些添加和列表逻辑:

// java描述

$scope.list = [];
$scope.addItem = function( item ) {
  $scope.list.push( { name : item.name, price : item.price } )
}

//查看

<div>
 <input ng-model="item.name" placeholder="name"></input>
 <input ng-model="item.price" placeholder="price"></input>
 <button ng-click="addItem( item )" >Add</button>
</div>

<div ng-repeat="it in list">
  {{ it.name }} {{ it.price }}
</div>
相关问题