简体   繁体   中英

How can I share the common code between a web and PhoneGap application, both written with Angular?

I have an Angular front-end that is being used as a website. However, I would also like to use it with PhoneGap to serve as a mobile application. The problem is that there are a few features in the mobile version that don't exist in the web version, such as a button to automatically insert the user's phone number into a text field.

More than 90% of both of these applications is the same, both in case of HTML/CSS and Javascript, and I have no idea how to keep this shared code in sync.

Is there a way to share the common code between these two applications (web and mobile) and yet allow them to change independently of each other?

You can load CSS and JS (Not HTML) from server like we load from CDNs, but It will raise a Slow-StartUp issue in App.

also consider offline scenario. If User opens your app when he/she is offline your app won't work because it can't find the resource which should be loaded from server.

you can sync your HTML/CSS/JS with server using a plugin have a look at https://microsoft.github.io/code-push/ maybe it could suffice your requirement.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM