@@ -83,7 +83,8 @@ class ElementBinder {
83
83
bool get hasDirectivesOrEvents =>
84
84
_usableDirectiveRefs.isNotEmpty || onEvents.isNotEmpty;
85
85
86
- void _bindTwoWay (tasks, expression, scope, dstPathFn, controller, formatters, dstExpression) {
86
+ void _bindTwoWay (tasks, expression, scope, directiveScope,
87
+ dstPathFn, controller, formatters, dstExpression) {
87
88
var taskId = tasks.registerTask ();
88
89
Expression expressionFn = _parser (expression);
89
90
@@ -99,14 +100,14 @@ class ElementBinder {
99
100
}
100
101
}, formatters: formatters);
101
102
if (expressionFn.isAssignable) {
102
- scope .watch (dstExpression, (outboundValue, _) {
103
+ directiveScope .watch (dstExpression, (outboundValue, _) {
103
104
if (! viewOutbound) {
104
105
viewInbound = true ;
105
106
scope.rootScope.runAsync (() => viewInbound = false );
106
107
expressionFn.assign (scope.context, outboundValue);
107
108
tasks.completeTask (taskId);
108
109
}
109
- }, context : controller, formatters: formatters);
110
+ }, formatters: formatters);
110
111
}
111
112
}
112
113
@@ -127,6 +128,7 @@ class ElementBinder {
127
128
128
129
void _createAttrMappings (directive, scope, List <MappingParts > mappings, nodeAttrs, formatters,
129
130
tasks) {
131
+ Scope directiveScope; // Only created if there is a two-way binding in the element.
130
132
mappings.forEach ((MappingParts p) {
131
133
var attrName = p.attrName;
132
134
var dstExpression = p.dstExpression;
@@ -141,7 +143,10 @@ class ElementBinder {
141
143
var bindAttr = bindAttrs["bind-${p .attrName }" ];
142
144
if (bindAttr != null ) {
143
145
if (p.mode == '<=>' ) {
144
- _bindTwoWay (tasks, bindAttr, scope, dstPathFn,
146
+ if (directiveScope == null ) {
147
+ directiveScope = scope.createChild (directive);
148
+ }
149
+ _bindTwoWay (tasks, bindAttr, scope, directiveScope, dstPathFn,
145
150
directive, formatters, dstExpression);
146
151
} else if (p.mode == '&' ) {
147
152
_bindCallback (dstPathFn, directive, bindAttr, scope);
@@ -162,8 +167,10 @@ class ElementBinder {
162
167
163
168
case '<=>' : // two-way
164
169
if (nodeAttrs[attrName] == null ) return ;
165
-
166
- _bindTwoWay (tasks, nodeAttrs[attrName], scope, dstPathFn,
170
+ if (directiveScope == null ) {
171
+ directiveScope = scope.createChild (directive);
172
+ }
173
+ _bindTwoWay (tasks, nodeAttrs[attrName], scope, directiveScope, dstPathFn,
167
174
directive, formatters, dstExpression);
168
175
break ;
169
176
0 commit comments