Javascript 将数组从ng repeat项传递给指令
我有以下指示:Javascript 将数组从ng repeat项传递给指令,javascript,angularjs,angularjs-directive,angularjs-ng-repeat,Javascript,Angularjs,Angularjs Directive,Angularjs Ng Repeat,我有以下指示: var productsTable = function() { return { restrict: 'E', scope: { products: '@' }, templateUrl: '../js/app/templates/products_table.html' }; }; 模板是一个简单的表: <table class="table table-str
var productsTable = function() {
return {
restrict: 'E',
scope: {
products: '@'
},
templateUrl: '../js/app/templates/products_table.html'
};
};
模板是一个简单的表:
<table class="table table-striped">
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>Quantity</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="product in products track by $index">
<td><% product.id %></td>
<td><% product.name %></td>
<td><% product.quantity %></td>
</tr>
</tbody>
</table>
问题是:指令无法识别产品数组,并且不显示表 试试这个
scope: {
products: '='
},
同样在Angular中,您应该使用{{}
而不是
您也可以使用ng bind=“{{variable name}}}”代替{{}}作为td中的属性,而不是
var entries
是$scope.entries
?哦,是的,我刚才给出了一个数组示例。entries
数组位于控制器内部…“它不显示表”?您的意思是模板根本没有加载,还是表中的数据没有显示?如果是前者,您是否在模块中注册了指令?@Patrick该表会出现,但不会显示数据!我想说的是:
var entries = [
{
id: 1,
products: [
{
id: 1001,
name: 'Product 1',
quantity: 30
},
{
id: 1002,
name: 'Product 2',
quantity: 3
}
]
},
{
id: 2,
products: [
{
id: 3001,
name: 'Product 3',
quantity: 450
}
]
}
];
scope: {
products: '='
},