我使用Angular2代码创建了cordova应用程序,当我在Android中部署APK时。应用程序不会加载任何内容。它一直显示加载....如果我在浏览器中使用angular2文件结构运行相同的angular2代码。它完美无缺。 Angular2代码包含一个简单的hello世界。
当我对移动设备进行远程调试时,我在控制台中看到以下错误。
Unhandled Promise rejection: Zone.assertZonePatched is not a function ; Zone: <root> ; Task: Promise.then ; Value: TypeError: Zone.assertZonePatched is not a function(…)consoleError @ zone.js:502
zone.js:504 Error: Uncaught (in promise): TypeError: Zone.assertZonePatched is not a function(…)consoleError @ zone.js:504
Cordova文件结构......
app.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
template: '<h1>My First Angular App2</h1>'
})
export class AppComponent { }
app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { FormsModule } from '@angular/forms';
@NgModule({
imports: [BrowserModule, FormsModule],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule { }
main.ts
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './appScripts/app.module';
const platform = platformBrowserDynamic();
platform.bootstrapModule(AppModule);
tsconfig.json
{
"compilerOptions": {
"noImplicitAny": false,
"noEmitOnError": true,
"removeComments": false,
"sourceMap": true,
"inlineSources": true,
"outDir": "../www/scripts/",
"target": "es5",
"module": "system",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"rootDir": "."
},
"exclude": [
"typings/browser.d.ts",
"typings/browser"
]
}
typings.json
{
"globalDependencies": {
"core-js": "registry:dt/core-js#0.0.0+20160725163759",
"jasmine": "registry:dt/jasmine#2.2.0+20160621224255",
"node": "registry:dt/node#6.0.0+20160909174046"
}
}
的package.json
{
"name": "angular2-lectron-package",
"version": "1.0.0",
"description": "Angular2 with ElectronPackage",
"repository": {
"type": "git",
"url": ""
},
"main": "main.js",
"author": "na",
"license": "na",
"dependencies": {
"@angular/common": "2.0.0",
"@angular/compiler": "2.0.0",
"@angular/core": "2.0.0",
"@angular/forms": "2.0.0",
"@angular/http": "2.0.0",
"@angular/platform-browser": "2.0.0",
"@angular/platform-browser-dynamic": "2.0.0",
"@angular/router": "3.0.0",
"@angular/upgrade": "2.0.0",
"core-js": "^2.4.1",
"reflect-metadata": "^0.1.3",
"rxjs": "5.0.0-beta.12",
"systemjs": "0.19.27",
"zone.js": "^0.6.23",
"angular2-in-memory-web-api": "0.0.20",
"bootstrap": "^3.3.6",
"gulp": "^3.9.0"
},
"devDependencies": {
"concurrently": "^2.2.0",
"lite-server": "^2.2.2",
"typescript": "^2.0.2",
"typings":"^1.3.2"
}
}
的index.html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
<title>Hello World</title>
</head>
<body>
<my-app>Loading...</my-app>
<!-- 1. Load libraries -->
<!-- IE required polyfills, in this exact order -->
<script src="js/angularScripts/shim.min.js"></script>
<script src="js/angularScripts/zone.js"></script>
<script src="js/angularScripts/system.src.js"></script>
<!--<script src="https://unpkg.com/zone.js@0.6.23?main=browser"></script>-->
<script src="js/angularScripts/Reflect.js"></script>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
</body>
</html>
index.js
function onDeviceReady() {
System.config({
paths: {
// paths serve as alias
'npm:': 'js/angularScripts/'
},
// map tells the System loader where to look for things
map: {
// our app is within the app folder
app: 'scripts',
// angular bundles
'@angular/core': 'npm:core.umd.js',
'@angular/common': 'npm:common.umd.js',
'@angular/compiler': 'npm:compiler.umd.js',
'@angular/platform-browser': 'npm:platform-browser.umd.js',
'@angular/platform-browser-dynamic': 'npm:platform-browser-dynamic.umd.js',
'@angular/http': 'npm:http.umd.js',
'@angular/router': 'npm:router.umd.js',
'@angular/forms': 'npm:forms.umd.js',
// other libraries
'rxjs': 'npm:rxjs',
'angular2-in-memory-web-api': 'npm:angular2-in-memory-web-api',
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
app: {
main: './main.js',
defaultExtension: 'js'
},
rxjs: {
defaultExtension: 'js'
},
'angular2-in-memory-web-api': {
main: './index.js',
defaultExtension: 'js'
}
}
});
//System.import('app/app').then(null, console.error.bind(console));
//System.import('app/main').catch(function (err) { console.error(err); });
System.import('app/main').then(null, console.error.bind(console));
}
document.addEventListener("deviceready", onDeviceReady, false);