AngularJS and Windows 8 Route Error

I am trying to create an HTML5 / JS / CSS3 application with angularJS on Windows 8.1 with visual studio 2012. I am now stuck when sending parameters to other views.

When googleing, I see a few examples using <a href="#/page/{{:pageId}}">link</a> When I do this in my Windows 8 application and clicking on the link, I get the following error.

No applications installed to open this type of link (unsafe)

When I put the code {{:pageId}} between the tags A, it shows my identifier.

app.js

 var myApp = angular.module('myApp', ['ngRoute', 'ngResource']); myApp.config(['$routeProvider', function($routeProvider) { $routeProvider.when("/", { templateUrl: "views/home.html" }) .when("/page/:pageId", { templateUrl: "views/page.html" }) .otherwise({ redirectTo: "/" }); }]); 

What is the solution to solve this problem?

- update -

I debugged a bit more. Everything works fine in the browser. In visual studio, I found the following:

 <a class="ng-binding" href="unsafe:ms-appx://3595d292-0235-47cd-8db7-cb3019f29114/www/index.html#/page/1" data-ng-href="#/page/1">Select</a> 

It looks like VS is adding some code. In the source, I did not include the href element

I changed the link and everything seems fine, the correct variable is also loaded. Only VS continues to add "unsafe:" in the second part of the link.

+6
source share
1 answer

The problem is solved!

it seems that ms-appx being added by ms is causing the problem. This is resolved by adding this following code.

AngularJS 1.2

 app.config(['$compileProvider', function($compileProvider) { $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|file|ms-appx):/); }]); 

For 1.1.x and 1.0.x use urlSanitizationWhitelist.

If you use PhoneGap, do not forget to add the file except https ?, otherwise the links will not work.

+11
source

Source: https://habr.com/ru/post/956716/


All Articles