如何将ng-repeat中的数据传递给数据属性?
请参阅下面我的目标。
抱歉格式不佳,这是我第一次发布到StackOverflow。
<div class="row">
<div class="col-md-3" ng-repeat="p in controller.prod | filter:{state:'California'}">
<div class="card">
<div class="card-block">
<h3 class="card-title">{{p.productName}}</h3>
<h6 class="card-subtitle text-muted">${{p.price}}</h6>
<img ng-src="{{p.productImage}}" class="img-fluid">
</div>
<div class="card-block">
<div class="card-text">Product information<a
href="#"
class="card-link productItem btn btn-primary"
<!--Below is what i'm trying to accomplish -->
data-name="{{p.productName}}"
data-s="black"
data-price="{{p.price}}"
data-id="1">Add to Cart</a>
</div>
<br />
</div>
</div>
</div>
</div>
答案 0 :(得分:0)
你必须在控制器中的$ scope中分配一个数组,然后在你的html模板中用ng-reapeat绑定它,如下所示:
app.controller("myCtrl", function($scope) {
$scope.records = [
"Alfreds Futterkiste",
"Berglunds snabbköp",
"Centro comercial Moctezuma",
"Ernst Handel",
]
});
你的模板:
<h1 ng-repeat="x in records">{{x}}</h1>