I successfully managed to downgrade Angular 7 component to Angular 1, but I faced a little problem which I have tried to solve many ways.
My downgraded component has output parameter as follows:
@Output()isValid = new EventEmitter<boolean>();
and it is triggered as follows:
this.isValid.emit(false);
In my Angular 1 component, I used it after downgrading it as follows:
<downgrade-employee-selector (is-valid)="{{vm.validateEmployeeSelector($event)}}"> </downgrade-employee-selector>
self.validateEmployeeSelector = ($event) => {console.log($event);}
It is working fine but in the Angular 1 function $event
value is always undefined and I can not understand how it is working.
Actually the problem with your original implementation comes with the syntax on your AngularJS html.
I believe adding the specification of inputs and outputs in the downgradeComponent method (as per your own solution) does not change things.
However, if you properly specify your output's name in AngularJS standard (hyphenated instead of camel case), and you bind your controller's method without interpolation, it works like a charm.
In Angular component: @Output() isValid = new EventEmitter<boolean>();
In AngularJS template: <downgrade-employee-selector ... (is-valid)="vm.validateEmployeeSelector($event)"></downgrade-employee-selector>
When downgrading: directive('downgradeEmployeeSelector', downgradeComponent({ component: EmployeeSelectorComponent })
I found a solution for my problem as follows:
directive('downgradeEmployeeSelector', downgradeComponent({
component: EmployeeSelectorComponent,
inputs: ['selectedEmployeesIds', 'multiSelect', 'required'],
outputs: ['isValid', 'selectedEmployeesIdsChange']
})
<downgrade-employee-selector name="empSelector" [selected-employees-ids]="vm.selectedEmployeeIds" [required]="true" (is-valid)="vm.validateEmployeeSelector($event)"></downgrade-employee-selector>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With