简体   繁体   中英

AngularJS and Windows 8 route error

I'm trying to create a HTML5/JS/CSS3 App with angularJS on Windows 8.1 with visual studio 2012. I'm currently stuck on sending over parameters to other views.

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

No Apps are installed to open this type of link (unsafe)

When I put the {{:pageId}} code between the A tags it shows its ID.

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 a solution to solve this problem?

--update--

I have done some more debugging. In the browser it's all working fine. In visual studio I have 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>

Looks like VS is adding some code. In the source I haven't include the href item

I have changed the link and all seems fine, also the correct variable is loaded only VS keeps adding 'unsafe:' at the frond of the link.

Problem solved!

seems like the ms-appx that is being added by ms causes the problem. This is being resolved by addeing 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, remember to add file besides https?, otherwise, links will not work.

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