-
Notifications
You must be signed in to change notification settings - Fork 556
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get component instance from field onInit event #946
Comments
you can do it by assigning the component instance to field during component construction: @Component({
...
})
export class SelectComponent extends FieldType implement OnDestroy {
private _field: FormlyFieldConfig;
set field(field) {
this._field = field;
this._field.templateOptions.componentRef = this;
}
get field() { return this._field; }
...
ngOnDestroy() {
if (this.field && this.field.templateOptions.componentRef) {
delete this.field.templateOptions.componentRef;
}
}
} IMO using a separate service would be better ;). |
Thanks @aitboudad. It worked like a charm :) |
Update: added |
FormlyForm.html:2 ERROR TypeError: this.interceptTable is not a function |
} else if (t === 'object') { |
How to use lifecycle hooks in JSON-Schema in order to populate the options in the second selection field (backend API data) after the selection of the first field using the IDs. |
@aitboudad In the latest version, this is no longer necessary. Could you please clarify what to replace it with? |
I'm submitting a ... (check one with "x")
Hello there, first thank you all for the great library.
I have one question. Is there a way to get component instance from on init event? Basically i am trying to create Cascaded Select like the example but without settings the field.to.options. I have implement a custom select wrapper using another select component lib and on the init function subscribing to other select valueChanges and change the url of the select component and reload it to fetch the new data.
Here is the part of code to get the idea.
Is what trying to do doable? the field.component as i can see is a function not the action component instance.
The text was updated successfully, but these errors were encountered: