我正在尝试弄清楚如何在指令和转发器之间创建双向绑定(bind)。我一直在尝试在互联网上找到的各种东西。这就是我现在所拥有的,但它没有将 item.myDate 传递到需要它的模板。
这应该如何完成?
HTML
<tr ng-repeat="item in items">
<td>
<mydirective dateModel="item.myDate"></mydirective>
</td>
</tr>
JS
app.directive("mydirective", function(){
return {
restrict:'E',
scope:{dateModel: "&"},
template:'<input class="date" ng-model="{{dateModel}}">',
};
});
最佳答案
进行此更改。
1.
<mydirective date-model="item.myDate"></mydirective>
2.
app.directive("mydirective", function(){
return {
restrict:'E',
scope:{dateModel: "="},
template:'<input class="date" ng-model="dateModel">',
};
});
请引用Plunker
关于javascript - 如何将模型传递给 Angular.js 中的指令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32330934/