Ionic StorageModule no data after update - ionic-framework

for the update of an ionic app from 5.3.4 to 6.1.13, also the ionic storage package changed from #ionic/storage (version 2) to #ionic/storage-angular (version 3). The whole app works fine, however I am unable to get already saved data with the new storage-module:
Old App (Ionic 5)
package.json:
"#angular/core": "~9.1.6",
"#ionic/angular": "^5.3.4",
"#ionic/storage": "^2.3.1",
app.module:
import { IonicStorageModule } from '#ionic/storage';
#NgModule({
...
imports: [
IonicModule.forRoot(),
IonicStorageModule.forRoot({
name: '__mydb',
driverOrder: ['sqlite', 'websql', 'indexeddb'],
}),
...
New App (Ionic 6, new angular-storage module)
package.json:
"#angular/core": "^14.0.5",
"#ionic/angular": "^6.1.13",
"#ionic/storage-angular": "^3.0.6",
app.module:
import { Drivers } from '#ionic/storage';
import { IonicStorageModule } from '#ionic/storage-angular';
#NgModule({
...
imports: [
IonicStorageModule.forRoot({
name: '__mydb',
driverOrder: [CordovaSQLiteDriver._driver, Drivers.IndexedDB, Drivers.LocalStorage],
}),
...
I even tried to downgrade to the old storage package (same version as in old app), still I am unable to retrieve the already saved data:
New App (Ionic 6, old storage module)
package.json:
"#angular/core": "^14.0.5",
"#ionic/angular": "^6.1.13",
"#ionic/storage": "2.3.1",
app.module:
import { IonicStorageModule } from '#ionic/storage';
#NgModule({
...
imports: [
IonicStorageModule.forRoot({
name: '__mydb',
driverOrder: ['sqlite', 'websql', 'indexeddb'],
}),
...
I would appreciate any insights / tips, the database name did not change and the data is still there, because if I install the old version again all data is retrieved successfully. But If I try to get the data (same key) with the updated ionic app, regardless of old or new storage package, I can't retrieve the data
Saving / retrieving new data with the new storage module works fine as well!
Testes with both IOS and Android

Related

Ionic 5 Capacitor FileTransfer

I'm running in the browser an ionic 5 APP using capacitor and I'm trying to use the file transfer functionality. I follow the documentation https://ionicframework.com/docs/native/file-transfer and configure my app using capacitor. Thus running:
npm install cordova-plugin-file-transfer
npm install #ionic-native/file-transfer
ionic cap sync
In my app.module, I registered the providers:
import { FileTransfer } from '#ionic-native/file-transfer/ngx';
import { File } from '#ionic-native/file/ngx';
...
providers: [
StatusBar,
SplashScreen,
...
FileTransfer,
File
],
Note that I also installed the native file package, so in total I have the following 4 new packages:
"#ionic-native/file": "^5.27.0",
"#ionic-native/file-transfer": "^5.27.0",
"cordova-plugin-file": "^6.0.2",
"cordova-plugin-file-transfer": "^1.7.1",
My code in the component is:
import { Input, Component } from '#angular/core';
import { FileTransfer, FileTransferObject } from '#ionic-native/file-transfer/ngx';
import { File } from '#ionic-native/file/ngx';
#Component({
selector: 'app-order-detail-order-card',
templateUrl: './order-detail-order-card.page.html'
})
export class OrderDetailOrderCardPage {
#Input() pdfUrl: string;
#Input() orderCardId: string;
constructor(private transfer: FileTransfer, private file: File) { }
public downloadFile(): void {
const fileTransfer: FileTransferObject = this.transfer.create();
fileTransfer.download(this.pdfUrl, this.file.applicationDirectory + `${orderCardId}.pdf`).then((entry) => {
console.log('download complete: ' + entry.toURL());
}, (error) => {
// handle error
});
}
}
When I run the app in the browser, I get the following warning and I'm not sure whether the file should donwload somewhere?
common.js:284 Native: tried calling SplashScreen.hide, but Cordova is not available. Make sure to include cordova.js or run in a device/simulator
Even if I don't get the file, I would be expecting to see the "download complete" message. It's not very clear to me as to whether I have to configure something else in my app to be able to run it locally or I have to use this functionality ONLY in either the emulator or the device itself.
What else needs to be configured to get this to work?
common.js:284 Native: tried calling SplashScreen.hide, but Cordova is not available. Make sure to include cordova.js or run in a device/simulator
this means that you are using the browser emulator which doesn't have any splashscreen, you can totally ignore that warning ( you won't get it using a simulator or a real device).
You should paste the html section of that page too, because probably the download doesn't start because an incomplete url and it doesn't proceed with the "then()"
maybe i'm wrong, but it can be possible.

Ionic native device plugin returns all nulls in all platforms

I'm using #ionic-native/device plugin in my ionic application in order to detect the underlying device running the application.
However, when I try to use it I get the Device object with all properties set to null.
Note:
this is NOT a duplication of This question since the problem occurs even when running cordova run browser or running in android...
I've installed the #ionic-native/device plugin and used it as follows:
App.module.ts:
import { Device } from '#ionic-native/device/ngx';
#NgModule({
// ...
providers: [
Device,
]
//...
})
export class AppModule { }
App.component.ts:
constructor(private device: Device) {
console.log('Device is: ', this.device);
}
package.json:
"dependencies": {
...
"#ionic-native/core": "^5.24.0",
"#ionic-native/device": "^5.26.0"
}
What is missing?
i suggest you to try this since, the method ready of the platform object helps you to wait all the plugins to be ready in order to execute your code.
don't forget this in your constructor params list : "private platform : Platform"
this.platform.ready().then(()=>{
console.log('Device is: ', this.device);
}

Type 'AppVersionOriginal' is not assignable to type 'Provider'. Type 'AppVersionOriginal' is missing the following properti

I have created new Ionic 3 application using the latest version of Ionic CLI v4.9.0 using below
$ ionic start Ionic3Project blank --type ionic-angular
which create V4 Ionic project by default.
Then I followed steps for Native App Version Plugin here
Faced following console error when imported in app.module.ts file
Uncaught Error: Invalid provider for the NgModule 'AppModule' - only instances of Provider and Type are allowed, got: [StatusBar, ?[object Object]?, ...]
at syntaxError (compiler.js:486)
at compiler.js:15784
at Array.forEach (<anonymous>)
at CompileMetadataResolver._getProvidersMetadata (compiler.js:15752)
at CompileMetadataResolver.getNgModuleMetadata (compiler.js:15320)
at JitCompiler._loadModules (compiler.js:34413)
at JitCompiler._compileModuleAndComponents (compiler.js:34374)
at JitCompiler.compileModuleAsync (compiler.js:34268)
at CompilerImpl.compileModuleAsync (platform-browser-dynamic.js:239)
at PlatformRef.bootstrapModule (core.js:5578)
app.module.ts file
import { BrowserModule } from '#angular/platform-browser';
import { ErrorHandler, NgModule } from '#angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { SplashScreen } from '#ionic-native/splash-screen';
import { StatusBar } from '#ionic-native/status-bar';
import { AppVersion } from '#ionic-native/app-version';
import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
#NgModule({
declarations: [
MyApp,
HomePage
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp)
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage
],
providers: [
StatusBar,
AppVersion, <-- Error [[ts]
Type 'AppVersionOriginal' is not assignable to type 'Provider'.
Type 'AppVersionOriginal' is missing the following properties from type 'FactoryProvider': provide, useFactory [2322]]
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler}
]
})
export class AppModule {}
UPDATE:Finally I found solution and explanation of this issue here :P
This issue is because of ionic new update(releasing ionic 4)
You have to import your plugins for ionic 3 like this:
import { PluginName} from '#ionic-native/pluginName/ngx';
More info here
This error is thrown because of the new update of ionic 4.
The above given solution would work perfectly.
But, this must be done throughout the project to avoid this error.
The other way could be to roll back to plugin's previous version.

Ionic button showing 'ion-button' is not a known element

I am new to ionic, it seems like a silly question but I need some help
Using some simple button is throwing error. I am using ionic 4.0.
'ion-button' is not a known element:
1. If 'ion-button' is an Angular component, then verify that it is part of this module.
2. If 'ion-button' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '#NgModule.schemas' of this component to suppress this message.
<ion-button color="primary">Primary</ion-button>
I think the solution is importing Ionic module in the respective module imports
import { IonicModule } from '#ionic/angular'; <--add this line
#NgModule({
imports: [
CommonModule,
FormsModule,
IonicModule, <-- add this line
],
})
Try this,
<button ion-button color="primary">Primary</button>
In order to avoid that error message:
Import CUSTOM_ELEMENTS_SCHEMA into app.modules.ts:
import { ErrorHandler, NgModule, CUSTOM_ELEMENTS_SCHEMA } from '#angular/core';
Add schema: [CUSTOM_ELEMENTS_SCHEMA] to app.modules.ts as below:
#NgModule({
declarations: [
MyApp,
HomePage
],
imports: [
BrowserModule,
HttpClientModule,
MomentModule,
IonicModule.forRoot(MyApp),
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage
],
providers: [
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler},
],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
I've run into this too. Your solution is not the best one as the new Ionic 4 way is to use <ion-button> (https://beta.ionicframework.com/docs/components/#button).
It does work for me fine in a page I have under /src/app/my-page/my-page.html, but when I put it in /src/shared/components/my-comp/my-comp.html it gives the error. The odd thing is that I have other Ionic elements in the same page <ion-grid>, <ion-row> and <ion-col>. Also, this code used to be in my-page.html where it worked without error.
FYI, MyComponent is in components.module.ts as a declaration and an export. Not sure yet what I am missing...
UPDATE 1: Neither moving the components directory under src nor under src/app made any difference.
UPDATE 2: This is my environment:
ionic (Ionic CLI) : 4.0.6
Ionic Framework : #ionic/angular 4.0.0-beta.2
#angular-devkit/core : 0.7.2
#angular-devkit/schematics : 0.7.2
#angular/cli : 6.1.2
#ionic/ng-toolkit : 1.0.0
#ionic/schematics-angular : 1.0.1
UPDATE 3: Still broken in this environment:
ionic (Ionic CLI) : 4.1.0
Ionic Framework : #ionic/angular 4.0.0-beta.3
#angular-devkit/core : 0.7.2
#angular-devkit/schematics : 0.7.2
#angular/cli : 6.1.2
#ionic/ng-toolkit : 1.0.6
#ionic/schematics-angular : 1.0.5
UPDATE 4: After much trial and error, I had to add schemas: [CUSTOM_ELEMENTS_SCHEMA] to my components.module.ts file. I was able to leave the directory structure as-is. I'm not sure why this is required for this scenario, though.
It seems you are not importing the ionicModule in the component module. So, Import the IonicModulein the module.ts, rest of the things will work fine
Import your custom component in the parent module. for example in your app.module.ts:
declarations: [MyComponent],
exports: [
PopoverComponent,
]
yes try this
<button ion-button color="primary">Primary</button>
In Ionic 5, I have a same problem when I build with --prod option.
Since *.module.ts file is not available in components in Ionic 5, I need to add shared module for components and then add CUSTOM_ELEMENTS_SCHEMA schema to that shared module.
ionic g module modules/shared
cat shared.module
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '#angular/core';
import { CommonModule } from '#angular/common';
import { FooComponent } from '../../components/foo/foocomponent.component'; <== Add your components
#NgModule({
declarations: [FooComponent], <== Add your components
imports: [
CommonModule
],
exports: [FooComponent], <== Add your components
schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
export class SharedModule { }
I was having this problem in a library that I was building
because I forgot to export the module of that was importing the IonicModule and exporting my component.
So, in my module was importing Ionic lib and exporting my component as below.
import { CommonModule } from '#angular/common';
import { NgModule } from '#angular/core';
import { IonicModule } from '#ionic/angular';
import { MyComponent } from './my.component';
#NgModule({
declarations: [
MyComponent,
],
imports: [
CommonModule,
IonicModule,
],
exports: [
MyComponent,
],
})
export class MyModule {
}
And in the public-api.ts file of my lib, I should have something like this
export { MyModule } from './lib/my.module'; // <--- exporting my module
export { MyComponent } from './lib/my.component';
My issue was that there were errors prior to this error that seemed to cascade down. The error I had was some elements in the declarations that should have been in the providers. Also, one of these was marked private in the constructor when it should have been public.
#NgModule({
imports: [
IonicModule,
CommonModule,
FormsModule,
RouterModule.forChild([{ path: '', component: DevicesPage }]),
DevicesPageRoutingModule,
TranslateModule.forChild()
],
declarations: [DevicesPage --> remove BLE, LocationAccuracy, DeviceManagerService ],
providers: [BLE, LocationAccuracy, DeviceManagerService] <--Add
})
I was stuck on this for a little while as well until I realized that the problem was I did not create the Ionic Angular project properly. you have to include --type=angular
https://github.com/ionic-team/ionic-cli
exp:
ionic start myApp tabs --type=angular
I faced similar issue after ionic 4, So I added the CUSTOM_ELEMENTS_SCHEMA in app.modules.ts. Then it worked fine
app.module.ts
providers: [
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler},
SpineRestServiceProvider,
FingerprintAIO
],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
Should add in app.module.ts
import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '#angular/core';
providers: [
StatusBar,
SplashScreen,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
],
schemas: [CUSTOM_ELEMENTS_SCHEMA] ==> add line**

Lazy loading 3rd party component in loaded page (Ionic)

The app working when i run ionic cordova run android --device but gives error when i try ionic cordova run android --prod --release
I am trying use ng2-qrcode into my lazy loaded page
Error: Unexpected value 'QRCodeComponent in
D:/qrstore/node_modules/ng2-qrcode/dist/ng2-qrcode.d.ts' declared by
the module 'ItemDetailPageModule in
D:/qrstore/src/pages/item-detail/item-detail.module.ts'. Please add a #Pipe/#Directive/#Component annotation.
at Error (native)
at syntaxError (D:\qrstore\node_modules\#angular\compiler\bundles\compiler.umd.js:1729:34)
at D:\qrstore\node_modules\#angular\compiler\bundles\compiler.umd.js:15625:40
at Array.forEach (native)
at CompileMetadataResolver.getNgModuleMetadata (D:\qrstore\node_modules\#angular\compiler\bundles\compiler.umd.js:15607:54)
at addNgModule (D:\qrstore\node_modules\#angular\compiler\bundles\compiler.umd.js:24403:58)
at D:\qrstore\node_modules\#angular\compiler\bundles\compiler.umd.js:24414:14
at Array.forEach (native)
at _createNgModules (D:\qrstore\node_modules\#angular\compiler\bundles\compiler.umd.js:24413:26)
at analyzeNgModules (D:\qrstore\node_modules\#angular\compiler\bundles\compiler.umd.js:24288:14)
ionic info
#ionic/cli-utils : 1.12.0
ionic (Ionic CLI) : 3.12.0
global packages:
cordova (Cordova CLI) : 7.0.1
local packages:
#ionic/app-scripts : 3.0.0
Cordova Platforms : android 6.2.3
Ionic Framework : ionic-angular 3.7.1
System:
Android SDK Tools : 25.2.3
Node : v6.9.4
npm : 3.10.8
OS : Windows 10
Misc:
backend : pro
item detail module
import { NgModule } from '#angular/core';
import { IonicPageModule } from 'ionic-angular';
import { ItemDetailPage } from './item-detail';
import { HttpModule, Http } from '#angular/http';
//native
import { File } from '#ionic-native/file';
import { FilePath } from '#ionic-native/file-path';
import { SQLite } from '#ionic-native/sqlite';
//providers
import { ItemsProvider, LabelsProvider, SQLiteDatabaseProvider } from '../../providers/providers';
//components
import { ItemCreatePage } from '../item-create/item-create';
import { QRCodeComponent } from 'ng2-qrcode'
//directive
import { AbsoluteDragDirective } from '../../directives/absolute-drag/absolute-drag';
#NgModule({
declarations: [
ItemDetailPage,
QRCodeComponent,
AbsoluteDragDirective
],
imports: [
IonicPageModule.forChild(ItemDetailPage),
HttpModule
],
exports: [
ItemDetailPage
],
entryComponents: []
,
providers:[
ItemsProvider,
SQLite,
SQLiteDatabaseProvider,
File,
FilePath
]
})
export class ItemDetailPageModule {}
ng2-qrcode is no longer maintained and does not work with the AoT compiler of angular (which is used when you build your app with --prod). But there is a drop in replacement which is built for usage in Ionic3/Angular4+ projects which use the AoT compiler: angularx-qrcode. It is based on the same library and provides the same API.
Add it as follows:
npm install angularx-qrcode --save
And to use it import it in your NgModule:
import { QRCodeModule } from 'angularx-qrcode';
And then add it to the imports array:
imports: [
QRCodeModule
],
I'm the author of angularx-qrcode mentioned above.
For those coming here and using the angularx-qrcode-package, I prepared a working angular-app for angular5/6 to have an easier start:
https://github.com/Cordobo/angularx-qrcode-sample-app
master-branch: latest angular, at the time of posting angular6
angular5-branch: you guessed it, is for angular5
HTH