Skip to content

NativeScript forms doesn't work in lazy loaded modules #735

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

Closed
chrillewoodz opened this issue Apr 3, 2017 · 12 comments
Closed

NativeScript forms doesn't work in lazy loaded modules #735

chrillewoodz opened this issue Apr 3, 2017 · 12 comments
Assignees
Labels

Comments

@chrillewoodz
Copy link

I've done A LOT of digging now and it seems like you guys have some problems with lazy loaded modules because NOTHING seems to work in them. FormBuilder works in the app.component.html/ts files but as soon as I put the very same code in a lazy loaded module it stops working. The FormBuilder values aren't getting populated despite the values changing inside the text fields.

The ActionBar is not getting picked up either, can't change title, put a go back button or anything inside a lazy loaded module. I haven't tried more stuff but I'm assuming that they will break as well based on these recent findings.

I tried downloading this repo which has a working FormBuilder example set up:

https://github.com/skywidesoft/ns-formcontrol-demo

It works, BUT, then I tried moving the very same code into a lazy loaded module and it stops working.

I use this to lazy load the module with a string (this is provided in the app.module.ts:

providers: [
    {
      provide: NgModuleFactoryLoader, 
      useClass: NSModuleFactoryLoader
    }
]

Here is my example app that uses lazy loading:

https://github.com/andresfleat/native-app/tree/sprint1

Look inside the +login module for the code that isn't working, or +register.

Please take a look at this as quick as possible so that me and others with the similar issues can move forward in our development instead of tearing our eyes out, cheers. If you need more info let me know and I'll try to provide it.

@tsonevn
Copy link
Contributor

tsonevn commented Apr 5, 2017

Hi @chrillewoodz,
Thank you for reporting this issue.
I tested this case and unfortunately I have to confirm that this is a real issue while using lazy loading and nativescript-angular/forms.
We will research what is causing this behavior. For further info, you could keep track on the issue.

@chrillewoodz
Copy link
Author

Ok that really is unfortunate, I hope this gets resolved as quickly as possible.

@chrillewoodz
Copy link
Author

chrillewoodz commented Apr 8, 2017

@tsonevn Now I have the same problem even without lazy loading..

@tsonevn
Copy link
Contributor

tsonevn commented Apr 10, 2017

Hi @chrillewoodz,
Could you provide sample project, where the problem could be reproduced, which could be debugged locally?

@sis0k0 sis0k0 self-assigned this Apr 11, 2017
@sis0k0 sis0k0 added question and removed bug labels Apr 11, 2017
@sis0k0 sis0k0 changed the title Nothing or very little seems to work in lazy loaded modules NativeScript forms doesn't work in lazy loaded modules Apr 11, 2017
@sis0k0
Copy link
Contributor

sis0k0 commented Apr 11, 2017

Hi @chrillewoodz,

The reason that the forms were not working is that the NativeScriptForms module wasn't imported in the lazy loaded module. Since the module is lazy loaded and not imported by another one, it doesn't inherit the modules imported in the parent module (AppModule in the case).
I forked the native-app repo you provided and made the required fixes. Check out the last two commits with their commit messages here. Feel free to ping me on NativeScript community slack if you have any questions :)

@sis0k0 sis0k0 closed this as completed Apr 11, 2017
@chrillewoodz
Copy link
Author

@sis0k0 Did you also manage to solve the action bar problem?

@sis0k0
Copy link
Contributor

sis0k0 commented Apr 11, 2017

Here is a working example in our sdk-examples of using action bar within lazy loaded module:
https://github.com/NativeScript/nativescript-sdk-examples-ng/tree/release/app/ui-category/action-bar

@chrillewoodz
Copy link
Author

@sis0k0 Thank you so much! Action bar started working automatically once I'd fixed the issues with the module imports. Now we can really get this project going :D

@nikis
Copy link

nikis commented Dec 21, 2017

Its very unclear how to use form* directives at all and i think its good to give details and examples in documentation.

@rohanrichards
Copy link

All of these links appear dead and I now have the same issue, can anyone help me out?

@vidrepar
Copy link

vidrepar commented Aug 16, 2018

Hey @rohanrichards, you should import NativeScriptCommonModule into any lazy loaded module.

A simple shared.module.ts which would be imported into every lazy loaded module would look like this:

import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core';
import { NativeScriptFormsModule } from 'nativescript-angular/forms';
import { ReactiveFormsModule } from '@angular/forms';
import { NativeScriptCommonModule } from '../../node_modules/nativescript-angular/common';

@NgModule({
  imports: [
    NativeScriptCommonModule,
    NativeScriptFormsModule,
    ReactiveFormsModule,
  ],
  exports: [
    NativeScriptCommonModule,
    NativeScriptFormsModule,
    ReactiveFormsModule,
  ],
  declarations: [],
  schemas: [
    NO_ERRORS_SCHEMA
  ]
})
export class SharedModule { }

And ActionBar starts working... :)

@jeffswitzer
Copy link

A bunch of my [(ngModel)] broke after migrating to lazy loading. For me I was under the impression that having the following in my main module (not lazy loaded):

imports: [
    NativeScriptFormsModule
]

implied that it didn't have to be in each of the lazy loaded modules. This seems to not be the case as adding

imports: [
    NativeScriptFormsModule
]

to each of the lazy loaded modules fixed things. Anyways, it would help if the docs clarified what's required or how this works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants