Reputation: 1991
I'm developing on windows 10 using VS code, I have android studio setup with android emulator nexus 5 API 24
I used angular-cli to create a new angular 2 app:
ng new angular2-cordova-test
In the project folder I used Cordova cli to create a new Cordova project:
cordova create cordova com.example.cordova cordova
cordova platform add android --save
cordova build
From root directory I built the angular 2 app into the Cordova www
directory
ng build --prod --output-path=cordova/www/
When I run app from cordova
directory into emulator:
cordova emulate android
I got Loading...
in the emulator, and app in not working
I think this has something to do with ES6 and emulator webview
how can I fix this? thanks in advance
Upvotes: 4
Views: 2575
Reputation: 1991
Actually, I asked this question rephrased here:
https://stackoverflow.com/questions/40470766/angular-2-and-cordova
which is closed for weired reasons!! so the answer there is in the comments
The problem was very trivial, the HTML formed by the angular 2 project contained:
<base href="/">
this is what caused the problem, just remove it
also in the way to solve the problem I learned how to:
it was a good experiment
update:
after getting into a situation of building angular + cordova + routing, Parth Ghiya's hint is a must
I changed the meta tag to <base href=".">
and everything including routing worked just fine
Upvotes: 4
Reputation: 492
I used this to set the base: <base href="./">
. This worked for me. But you can also use <base href="file:///android_asset/www/" />
for android.
Finally i have a fully helpful suggestion to use the Chrome remote debugger to debug your mobile app. The console it tells everything.
Upvotes: 1
Reputation: 6949
Just use
if u remove the base href then your routes wont work in angular 2.
if u want to build, do
ng build --prod --base-href .
Upvotes: 3