Built-in storage module with Ionic 3 Lazy loading

My Ionic 3 app has about 10 pages and I implemented a lazy download function. Now I have a question, where about the Native Storage module . Do I need to import it into a file app.module.tsor is it normal if I import it every page module? What is the recommended way to use it and of course the best practice?

app.module.ts

@NgModule({
  declarations: [
    MyApp,
  ],
  imports: [
      IonicStorageModule.forRoot(),
  ],
+4
source share
1 answer

Just as you can see in the docs , it is recommended that you use Storage to add it to AppModule:

NgModule ( , src/app/app.module.ts):

import { IonicStorageModule } from '@ionic/storage';

@NgModule({
  declarations: [
    // ...
  ],
  imports: [      
    BrowserModule,
    IonicModule.forRoot(MyApp),
    IonicStorageModule.forRoot()
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    // ...
  ],
  providers: [
    // ...
  ]
})
export class AppModule {}

, :

import { Storage } from '@ionic/storage';

export class MyApp {
  constructor(private storage: Storage) { }

  ...

  // set a key/value
  storage.set('name', 'Max');

  // Or to get a key/value pair
  storage.get('age').then((val) => {
    console.log('Your age is', val);
  });
}

, , , , , AppModule app.component.ts, .


UPDATE

Angular docs:

, , ?

, , .

Angular , . , .

.

. , Angular .

Storage, ( ), , StatusProvider, public status: boolean .

( ), StatusProvider providers AppModule ( app.module.ts), StatusProvider . , status - , , , .

, StatusProvider providers , , StatusProvider. , status , ( ) .

+2

Source: https://habr.com/ru/post/1681213/


All Articles