-
Notifications
You must be signed in to change notification settings - Fork 33
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
Lazy loading causes ExpressionChangedAfterItHasBeenCheckedError (NG-ZORRO?) #15
Comments
Do you think you might manage to make a minimal repro of the issue on Stackblitz? |
Also I doubt that it's related to lazy loading but |
@maxime1992 I've created a new repository here https://github.com/lppedd/ngx-sub-form-test Hope Ivy will make debugging Angular Core easier too! Switching from debugging Java code to Javascript code has been a major struggle for me. |
@maxime1992 I wonder if this might actually be related to the thing I was talking about regarding not destroying the form item controls when the external value updates? Something to check perhaps. |
@maxime1992 @zakhenry Calling for
I wonder if this is an optimal solution at all. From
This would require a fix anyway, however. The problem I see with having to use the This
is also problematic with |
Hey @lppedd 👋 I took some time today to dig into that issue, thanks for the repro because it helped a lot. Every time there's an error What I found is related to that part of the lib: delay(0),
tap(changes => {
// ...
this.onChange(this.transformFromFormGroup(changes));
// ...
} Notice here that we've got the BUT, on that line // this is required to correctly initialize the form value
this.onChange(this.transformFromFormGroup(this.fg.value)); we do not have an equivalent of I believe the fix is simply to wrap that line into a Side notes: Few things I've noticed from your repro and that might be improved: 1 -
embrasse the lib and make a form on the top level component: const defaultPages: Page = {
families: [
{
name: 'Family 1',
values: [
{
id: '1',
value: 'Value 1',
},
{
id: '2',
value: 'Value 2',
},
],
},
],
};
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
})
export class AppComponent extends NgxSubFormComponent<{ page: Page }> {
formControls = {
page: new FormControl(defaultPages),
};
} and then HTML becomes: <form [formGroup]="formGroup">
<app-page [formControlName]="formControlNames.page"></app-page>
</form> 2 - Update from: @Component({
selector: 'app-page',
templateUrl: './page.component.html',
styleUrls: ['./page.component.scss']
})
export class PageComponent extends NgxSubFormComponent<{ wrapper: Page }> {
@Input()
public set page(page: Page) {
this.formGroup.setValue({
wrapper: page
})
}
protected formControls: Controls<{ wrapper: Page }> = {
wrapper: new FormControl()
};
} To: @Component({
selector: 'app-page',
templateUrl: './page.component.html',
styleUrls: ['./page.component.scss'],
providers: subformComponentProviders(PageComponent),
})
export class PageComponent extends NgxSubFormRemapComponent<Page, { wrapper: Page }> {
protected formControls: Controls<{ wrapper: Page }> = {
wrapper: new FormControl(),
};
protected transformToFormGroup(obj: Page): { wrapper: Page } {
return { wrapper: obj };
}
protected transformFromFormGroup(formValue: { wrapper: Page }): Page {
return formValue.wrapper;
}
} That kind of use case is exactly what |
@maxime1992 thanks for the advice! Regarding the error, wouldn't be better using, somehow, the |
I think it's one of those (rare) cases where Putting a So I think we end up with the same result, but a simpler API when using Also, if I was going to use
I guess it'd in the case where the top component is also extending That's why I think in that case
Can you explain why? |
…, wait for one tick before doing so This closes #15
@maxime1992 just because I'm also not an Angular expert so my opinions might be wrong. For the last part of my message, about
What do you think? Should I create another issue? |
Oups. Missed that part 🤐
Yes please, let's keep this thread focused on the error :) |
…, wait for one tick before doing so This closes #15
…, wait for one tick before doing so This closes #15
🎉 This issue has been resolved in version 2.1.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Even with this workaround, it seems that lazy loading a component doesn't work. At least that happens when using the NG-ZORRO Tab's lazy loading mechanism.
Usage example:
I'm trying to understand, but with no luck 'til now.
The text was updated successfully, but these errors were encountered: