skol-pro / ion-digit-keyboard-v2

A digital keyboard plugin to use in Ionic 2 applications.
MIT License
94 stars 40 forks source link

Ionic 3 - can't import globally to app.module.ts #6

Closed jans-y closed 7 years ago

jans-y commented 7 years ago

Hi,

I want to tell that this plugin is great!

I just started having a problem after using it on multiple pages.

I am using subscribe method to get pressed keys and when I import it to more than one page (lazy loaded), it's emitting more than one press.

The problem will probably be that I was declaring it for each page separately.

How should I import it to have it globally and at the same time using lazy loading? (each page has own module)

Thank you very much!

Definitely going to donate after resolving this issues ;-)

skol-pro commented 7 years ago

Hi jans-y ! Thank you, it really makes me happy people can use and enjoy the plugin I've made with fun ! :-)

There is some conceptual issues regarding life cycle with the plugin (by "issues" I mean "to improve"), and that's my top priority, hope I'm gonna have a time to refactor that this week-end !

Regarding your problem, by module you really mean that you're importing multiple @NgModule in your app, and that some of those modules are them-self importing the plugin, right ?

In that case, that's an excellent question ! But, from my mind, multiple module means multiple instances so it makes sense. Why not just importing the plugin in your main module (main app), and use a service or something to decide to display the keyboard if it "exists", otherwise the default keyboard ?

jans-y commented 7 years ago

Hi,

I am using lazy loading and that means that declaring in the app.module.ts is not enough.

I have solved the issue by creating shared module which exports keyboard module and it works without errors. shared.module.ts

@NgModule({
  imports: [
    CommonModule,
    IonicModule ],
  declarations: [ IonDigitKeyboard ],
  exports: [ IonDigitKeyboard ] //CommonModule
})
export class SharedModule { }

I don't know if it is correct solution but it works.

Only problem that I am experiencing is the issue where clicking button on the another page triggers undefined even after page before was unloaded and keyboard destroyed by your method.

skol-pro commented 7 years ago

Hi !

I think that’s a good solution and I actually think I’ll refactor the plugin to be a module, so that everything is embedded (services I’ll add, etc).

Sorry but I’m not sure I understood your last sentence ha ha, tired ? :-p

Le 29 avr. 2017 à 17:44, jans-y notifications@github.com a écrit :

Hi,

I am using lazy loading and that means that declaring in the app.module.ts is not enough.

I have solved the issue by creating shared module which exports keyboard module and it works without errors. shared.module.ts

@NgModule({ imports: [ CommonModule, IonicModule ], declarations: [ IonDigitKeyboard ], exports: [ IonDigitKeyboard ] //CommonModule }) export class SharedModule { } I don't know if it is correct solution but it works.

Only problem that I am experiencing is the issue where clicking button on the another page triggers undefined even after page before was unloaded and keyboard destroyed by your method.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/skol-pro/ion-digit-keyboard-v2/issues/6#issuecomment-298176603, or mute the thread https://github.com/notifications/unsubscribe-auth/AKINEaWGoNYyiQX2JpXcDB4a-rrSwqTIks5r01rugaJpZM4NF_BM.

jans-y commented 7 years ago

Sorry that I wasn't clear.

I have implemented ion-digit-keyboard element in the app.html.

On the particular pages, I have subscribed for the onHide and onClick event.

When browsing between pages, scrollToTop() inside onHide subscribe function breaks. (http://ionicframework.com/docs/api/components/content/Content/#scrollToTop)

That's also true for onClick. Subscriber from the closed page continues to function even after closing that page.

Thank you very much for your work!

Ionic: 3.2.1