fix(upgrade): correctly handle `=` bindings in `@angular/upgrade` (#22167)

Previously, having a `=` binding on an upgraded components would result
in setting the corresponding property to an EventEmitter function. This
should only happen for `&` bindings.
This commit rstrores the correct behavior.

Note:
The issue was only present in the dynamic version of `ngUpgrade`. The
static version worked as expected.
The error did not show up in tests, because in AngularJS v1.5.x a
function would be serialized to an empty string in interpolations, thus
making them indistinguishable from uninitialized properties (in the
view). The serialization behavior changed in AngularJS v1.6.x, making
the errors visible.

PR Close #22167
This commit is contained in:
George Kalpakas 2018-02-15 19:26:28 +02:00 committed by Victor Berchet
parent 8e1e040f72
commit f089bf5333
1 changed files with 4 additions and 2 deletions

View File

@ -174,9 +174,11 @@ class UpgradeNg1ComponentAdapter implements OnInit, OnChanges, DoCheck {
}
for (let j = 0; j < outputs.length; j++) {
const emitter = (this as any)[outputs[j]] = new EventEmitter<any>();
if (this.propOuts.indexOf(outputs[j]) === -1) {
this.setComponentProperty(
outputs[j], (emitter => (value: any) => emitter.emit(value))(emitter));
}
}
for (let k = 0; k < propOuts.length; k++) {
this.checkLastValues.push(INITIAL_VALUE);
}