Cordova application using Angular 2

angular, cordova, cordova-plugins

Solution

To add any Cordova plugin in agular project,

Edit main.ts to look like this:

if (environment.production) { enableProdMode(); } let onDeviceReady = () => { platformBrowserDynamic() .bootstrapModule(AppModule) .catch(err => console.error(err));

}; document.addEventListener("deviceready", onDeviceReady, false);

For any plugin(for example Camera): on top, declare let navigator: any;

use: navigator.camera.getPicture(success, failure, { quality: 80 }); .

In index.html of the angular project add the following script.

`<script type="application/javascript" src="cordova.js"></script>` Note: The MIME type should be "application/javascript" not "text/javascript".

Build the project using the command

ng build --base-href . --prod --output-path ./Aditya/www/ Note: here Aditya is name of the cordova project

Now edit the index.html file inside Aditya/www/ folder of Cordova project to include MIME for all the script included.

type="application/javascript"

Now you are good to go.

Problem

Instead of ionic I would like to use cordova framework. So far, Step 1: I have created an angular 2 application. Step 2: I have created an cordova application and integrated angular 2 application in it. Its running successfully. Step 3: Next step is to load cordova.js file on load Step 4: Add cordova plugin(like camera , device ext) in my project. Step 1 and 2 completed. Please help me out to complete step 3 and step 4. When I call plugin its throws an error as follows,

Original source