我需要绑定数据以提交表格列中的表格。 我正在尝试绑定像这样的数据
<tr ng-repeat="domain in domainlist">
<td name="domain" ng-model="domain.domain" >{{domain.domain}}</td>
<td name="status" ng-model="domain.status" >{{domain.status}}</td>
<td name="price" ng-model="domain.price" >{{domain.price}}</td>
<td><button class="btn btn-success" ng-click="addCart()">Add To cart</button></td>
</tr>
但输出未定义。
答案 0 :(得分:1)
从td,ng-model中删除de-model仅适用于元素i / o
<强>控制器强>
.controller('myController', function($scope){
$scope.domainlist = [{domain: 'myDomain1', status: 1, price: 200},
{domain: 'myDomain2', status: 1, price: 250}];
});
<强> HTML 强>
<tr ng-repeat="domain in domainlist">
<td name="domain">{{domain.domain}}</td>
<td name="status">{{domain.status}}</td>
<td name="price">{{domain.price}}</td>
<td><button class="btn btn-success" ng-click="addCart()">Add To cart</button>
</td>
</tr>
答案 1 :(得分:0)
是的,删除ng-model并在addCart方法中将域作为参数传递,请参阅此处Plunker
答案 2 :(得分:0)
一些观察结果:
ng-model
与form elements
合作,例如input
,select
,checkbox
,radio
,etc..
{}
来绑定<td>
,<p>
,<span>
,etc..
<强>样本强>
var myApp = angular.module('myApp',[]);
myApp.controller('MyCtrl', function($scope) {
$scope.domainList = [{"domain": 'myDomain1', "status": 1, "price": 200},
{"domain": 'myDomain2', "status": 1, "price": 250}];
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="MyCtrl">
<table>
<tr ng-repeat="item in domainList">
<td>{{item.domain}}</td>
<td>{{item.status}}</td>
<td>{{item.price}}</td>
<td><button class="btn btn-success" ng-click="addCart()">Add To cart</button></td>
</tr>
</table>
</div>