Access tables from existing Database in provider function called in @App, OK in @page
Note: for support questions, please use one of these channels:
https://forum.ionicframework.com/ http://ionicworldwide.herokuapp.com/
Short description of the problem:
calling a provider function in @app providers that contains sqlStorage does not find the table in the specified database, but when this function is called from @page providers it finds the table i am looking for and using to store items.
calling like this:
this.storage = new Storage(SqlStorage, {name: 'my.db', existingDatabase: true});
also ran the following and tables are not included in the results
SELECT * FROM sqlite_master
What behavior are you expecting?
the provider called from @app find same tables as called from @page
Steps to reproduce:
- create a service, call sqlstorage on an existing database
- then call function from @page see results from table
- then call from @app and have error table not found.
insert any relevant code between the above and below backticks
Other information: (e.g. stacktraces, related issues, suggestions how to fix, stackoverflow links, forum links, etc)
Which Ionic Version? 1.x or 2.x
2 beta 3
Run ionic info from terminal/cmd prompt: (paste output below)
Cordova CLI: 6.0.0 Gulp version: CLI version 3.9.0 Gulp local: Local version 3.9.1 Ionic Version: 2.0.0-beta.3 Ionic CLI Version: 2.0.0-beta.19 Ionic App Lib Version: 2.0.0-beta.9 ios-deploy version: 1.8.5 ios-sim version: 5.0.7 OS: Mac OS X El Capitan Node Version: v5.7.0 Xcode version: Xcode 7.2 Build version 7C68
Hello! Thanks for opening an issue with us! So first just as a suggestion I personally wouldn't try to do things like sqlstorage calls in your @App. @App is like your bootstrapping class in Ionic 2. It sets up the application, loads all your pages, and serves as your "containing" component. Now on to the issue, I am going to make a test and test this for myself but I'm guessing that this is not working in your @App because of how the application is bootstrapped. Would you be able to provide your @App and your sqlstorage service so that I can see exactly what your code looks like? Thanks and I hope your enjoying Ionic 2!
where am I meant to call a service that polls from changes from my server on an interval basis then?
Thanks for the prompt response! (: Would you be able to provide you @App so that i can take a look at where you're calling it exactly? Are you calling it in the constructor?
http://hastebin.com/usevidaluc.coffee
Thanks! Where is the page that your also calling that service from, is it the rootpage? Also, do you have that service in the providers array on the @Page too?
looking at this is see what the issue actually is, the problem is the constructor of the service tries to load the sqlStorage before the app has done platform.load event. As dependency injection causes the service constructor to be called before platform ready event in turn breaking the expected results. My question now is where would i put http to globally poll a server.
Could you try taking the code that is currently in your constructor in the service and instead put it in ngOnInit? Here is an example of how to use ngOnInit:
` import {OnInit} from "angular2/core";
export class AwesomeService implements OnInit {
ngOnInit() {
//do stuff here instead of your constructor
}
}
`
Hello! As it has been a little while since there was any activity on this issue i will be closing it for now. Thanks for using Ionic!