Running on Windows Phone

The application created to this point runs fine inside the iOS and Android simulators and emulators. However, you will get an error if you try to run it on Windows Phone. This is because frameworks such as AngularJS, EmberJS, and KnockoutJS (among others) use properties of JavaScript that Microsoft has flagged as unsafe because they can cause common security issues (properties such as innerHTML and outerHTML). Thankfully, there is a fix.

The Microsoft Open Technologies (MS Open Tech) group has released a JavaScript shim called the Dynamic Content shim for Windows Store apps. It is a JavaScript file you run to mitigate the errors when using client-side scripts. The shim still achieves the fundamental goal set by the security model, but it allows your client side framework code to run.

The following walks you through using this shim.

1. Start by downloading the shim from the Git repository. It is a single file called winstore-jscompat.js. You can download it from the following URL:

https://github.com/MSOpenTech/winstore-jscompat.git

2. Open your project in Visual Studio. Copy the winstore-jscompat.js file into the scripts/lib directory.

3. Open the index.html file from the root of your project. Add a <script> tag near the top of the file (inside the <head> tag) before any other .js scripts are executed. This <script> tag should look like this.

<!-- dynamic content shim for Windows Store apps -->
<script src="scripts/lib/winstore-jscompat.js"></script>

You should now be able to run your application on a Windows Phone emulator or an actual device. Figure 25.21 shows the application running on a Windows Phone emulator.

Image

FIGURE 25.21 Use the winstore-jscompat.js shim to run your AngularJS (and related frameworks) on a Windows Phone.

At the time of writing, Ionic mentions that Windows Phone is on its roadmap. Most of it works. (It is just HTML5 and JavaScript.) However, Ionic does not currently support Windows Phone. This should change in the near future (and likely has already since this book was written). Therefore, you might run into anomalies with their controls. You can work through most of these.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset