Hi, I want to use the File API of Ionic in a DataManagament class - so I do have no constructor parameter
private file:File like I normally would. So I imported File and created a static private (because all variables and methods of the class shall be static) variable like this and one more variable:
private static file: File = new File();
public static test = DataManagement.file.dataDirectory;
When I try to use
in my Angular Component the app crashes. It shall not have to do with the os - windows - could it? Furthermore I want to ask if there is any better option to test the app with native features than compiling and installing the app every single time I change something…?
I don’t think this approach is viable. Ionic Native relies on being managed by Angular’s DI in order to implement its necessary initialization logic. I would recommend that you rearchitect
DataManagement so that it too is managed by DI, instead of trying to make it a manual Singleton.
So it is not recommended to instantiate a File object yourself?
The naming conventions here make things a bit confusing to discuss, but if by “a File” you mean “the ionic-native plugin object providing access to the cordova file plugin and documented here”, then “yes”. The bottom line here, I expect, is that you are trying to interact with Cordova before it is ready. Allowing DI to handle all your object lifecycles (and wrapping things inside chains off
Platform.ready()) will automatically make that problem go away.
Okey, thanks, I will try that!