【发布时间】:2014-02-05 19:22:13
【问题描述】:
我遇到了角度自定义指令的问题。
JS
app.directive('myElement', function () {
return {
scope: {
item: '=i'
},
restrict: 'EA',
replace: false,
template: '<td>Name: {{ item.name }}</td> <td>Age: {{ item.age }}</td>'
};
HTML
<div ng-controller="MyCtrl">
<table class="table table-hover" border=1>
<tr ng-repeat="p in people">
<td my-element i="p"></td>
</tr>
</table>
此模板不呈现为 2 个“TD”标签,它仅呈现来自 html 的“TD my-element”,其中包含绑定数据。
如果我将模板更改为
template: '<div>Name: {{ item.name }}</div> <div>Age: {{ item.age }}</div>'
页面在“TD my-element”内以 2 div“DIV”呈现
如果我让 replace=false 一切都消失了。
为什么 TD 的行为与 DIV 不同
【问题讨论】:
标签: javascript angularjs angularjs-directive