[英]Angular 2 in Phonegap doesn't work (plain javascript)
I build a website with angular 2 in plain javascript and everything it's working ok in browser, but when I try to build phonegapp app or use it with Phonegap Mobile app it doesn't work. 我用简单的javascript构建了一个带有角度2的网站,并且它在浏览器中工作正常,但是当我尝试构建phonegapp应用程序或将其与Phonegap Mobile应用程序一起使用时,它无效。
In index.html I have: 在index.html我有:
<body>
<app>Loading app...</app>
<!-- 1. Load libraries -->
<script src="libs/angular/2.0.0-beta.3/angular2-polyfills.js"></script>
<script src="libs/angular/2.0.0-beta.3/Rx.umd.js"></script>
<script src="libs/angular/2.0.0-beta.3/angular2-all.umd.js"></script>
<!-- 2. Load our 'modules' -->
<script src='app/services.build.js'></script> <!-- All our services, as server comunication -->
<script src='app/components.build.js'></script> <!-- All the components -->
<script src='app/app.component.js'></script> <!-- App component, main one -->
<script src='app/main.js'></script> <!-- Main -->
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript">
phonegapApp.initialize();
</script>
</body>
And on main.js I have: 在main.js我有:
var phonegapApp = {
initialize: function() {
this.bindEvents();
},
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
onDeviceReady: function() {
ng.platform.browser.bootstrap(AppComponent,[
ng.router.ROUTER_PROVIDERS,
new ng.core.Provider(ng.router.LocationStrategy, {useClass: ng.router.HashLocationStrategy})
]);
}
};
So I include ng.platform.browser.bootstrap
when device is ready. 因此,当设备准备好时,我会包含
ng.platform.browser.bootstrap
。 (Also tried with document.addEventListener('DOMContentLoaded', function() {...}
but with same result. (也尝试使用
document.addEventListener('DOMContentLoaded', function() {...}
但结果相同。
All that I can see it's Loading... so <app>Loading...</app>
it's not interpreted by angular. 所有我能看到它正在加载...所以
<app>Loading...</app>
它不是由角度解释的。
Do you have any idea what I should change to work? 你知道我应该改变什么工作吗? Thanks.
谢谢。
You need to add shims
to make it working on phonegap
. 您需要添加
shims
使它工作phonegap
。 That can be either es6-shim.js
/ es5-shim.js
这可以是
es6-shim.js
/ es5-shim.js
Probably that will solve your issue. 可能会解决您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.