使用模板的指令中更新NG-模型
我有一个实例化一个像这样的指令:
I have a directive that is instantiated like this:
<datepicker ng-model="foo"></datepicker>
里面的指令,日期选择器标签此模板替换为:
Inside the directive, the datepicker tag is replaced by this template:
template: '<div class="datepicker-wrapper input-append">' +
'<input type="text" class="datepicker" />' +
'<span class="add-on"><i class="icon-calendar"></i></span>' +
'</div>'
这是我想要绑定到NG-模型的值是输入字段的值。什么是去最好的办法,所以我保持NG-模型的数据双向绑定?
The value that I want ng-model bound to is the value of the input field. What is the best way to go about this so I maintain the two-way data binding of ng-model?
根据您的直通是多么复杂,你可以只使用=范围做一个本地名称和ngModel之间的双向绑定,就像这个小提琴:
Depending on how complicated your passthrough is, you can just use the = scope to do a bidirectional bind between a local name and ngModel, like in this fiddle:
我有一个时间地狱设立小提琴出于某种原因(第一次与角度尝试),但这里的钱拍:
I had a hell of a time setting up the fiddle for some reason (first time trying with angular) but here's the money shot:
template: '<div class="datepicker-wrapper input-append">'
+ '<input type="text" class="datepicker" ng-model="bar" />'
+ '<span class="add-on"><i class="icon-calendar"></i></span>'
+ '</div>',
scope: {
bar: '=ngModel'
},