Currently trying to figure out why this happens, but if I have an optionnal function binding (&?
) on a NG1 component then NG2 will put a EventEmitter on it :/
This is not what I expect and breaks some code we do when these are normally null
/undefined
.
Here is a example of what we have :
class MyController {
public onInit: () => string;
public onAction: () => void;
public resultFromNg2: string;
public onActionHasValue: boolean;
public typeOfOnAction: string;
public $onInit() {
this.resultFromNg2 = this.onInit();
this.onActionHasValue = this.onAction != null;
this.typeOfOnAction = typeof this.onAction;
}
}
export const ng1DemoComponent = {
selector: "ng1-demo",
template: `
<div>Hello, {{ $ctrl.username }}!</div>
<div>resultFromNg2: {{ $ctrl.resultFromNg2 }}</div>
<div>onActionHasValue: {{ $ctrl.onActionHasValue }} - typeof: {{ $ctrl.typeOfOnAction }}</div>
`,
bindings: {
username: "<",
onInit: "&?",
onAction: "&?"
},
controller: MyController
};
@Directive({
selector: ng1DemoComponent.selector
})
export class Ng1DemoComponentFacade extends UpgradeComponent {
@Input() username: string;
@Input() onInit: () => string;
@Input() onAction: () => void;
constructor(elementRef: ElementRef, injector: Injector) {
super(ng1DemoComponent.selector, elementRef, injector);
}
}
Testable environment : https://stackblitz.com/edit/angular-hybrid-upgrade-dpjv4p?file=ng1%2Fng1-demo.component.ts
In this code, I expect to have onAction
set to undefined
so I can assign my other property properly, but currently it's not working :/
I also tried removing the ?
, so from &?
to &
, but now it's NG1 who gives probably angular.noop
..
Any ideas on how I can make this work without rewriting stuff ?
Thanks a lot of any help given !
Note: We want to keep a part of our codebase in NG1, because it's not feasable for us to convert all of it right now with the codebase we have.