Using Angular with Cordova

2019-04-15 11:44发布

问题:

I am trying to add angular 5 to cordova and create a project. And no I DO NOT want to use ionic.

I am following the following tutorial on the web https://medium.com/@nacojohn/convert-your-angular-project-to-mobile-app-using-cordova-f0384a7711a6

when I run ng serve my app launches in the browser and when I do cordova build android my app is built successfully.

But as soon as I launch the app in an emulator I get the following error and a white screen

compiler.js:16014 Uncaught TypeError: undefined is not a function

Do let me know where is the issue?

Thanks

Note: I am simple using the started project generated by angular cli which is why I am not adding any code.

回答1:

If you can, try running it on a real device. Emulators have issues with outdated browsers which aren't compatible with Angular 5 browser support - https://angular.io/guide/browser-support. I tried the above and it was launching successfully on my device.

To sort this out, I enabled the ES6 support on older browsers by:

  1. Edit the polyfills.ts in your /src folder. Uncomment the following lines

import 'core-js/es6/symbol';

import 'core-js/es6/object';

import 'core-js/es6/function';

import 'core-js/es6/parse-int';

import 'core-js/es6/parse-float';

import 'core-js/es6/number';

import 'core-js/es6/math';

import 'core-js/es6/string';

import 'core-js/es6/date';

import 'core-js/es6/array';

import 'core-js/es6/regexp';

import 'core-js/es6/map';

import 'core-js/es6/weak-map';

import 'core-js/es6/set';

  1. Run the ng build command and finally cordova build android

The above steps sorted it for me.

Regards