小编Gav*_*oni的帖子

Angular.js aHrefSanitizationWhitelist不工作​​?

我正在尝试使用基本的Angular.js教程,但是我在设置url-schema的白名单时遇到了麻烦.

基本上我正在尝试将自定义方案(cust-scheme)添加到angular的白名单中,以避免它为url添加前缀unsafe:.

根据这个 StackOverflow上的答案,我只需要添加$compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|cust-scheme):/); 到应用程序的配置参数.

我尝试了以下方法:

'use strict';

/* App Module */

var phonecatApp = angular.module('phonecatApp', [
  'ngRoute',
  'ngSanitize',
  'phonecatAnimations',

  'phonecatControllers',
  'phonecatFilters',
  'phonecatServices'
]);

phonecatApp.config(['$routeProvider',
  function($routeProvider) {
    $routeProvider.
      when('/phones', {
        templateUrl: 'partials/phone-list.html',
        controller: 'PhoneListCtrl'
      }).
      when('/phones/:phoneId', {
        templateUrl: 'partials/phone-detail.html',
        controller: 'PhoneDetailCtrl'
      }).
      otherwise({
        redirectTo: '/phones'
      });
  }],
  ['$compileProvider',
  function( $compileProvider ) {   
    $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|cust-scheme):/);
    $compileProvider.imgSrcSanitizationWhitelist(/^\s*(https?|cust-scheme):/);
  }
]);
Run Code Online (Sandbox Code Playgroud)

但它不起作用.路由很好,但cust-scheme模式不是白名单.有什么我想念的吗?也许我在做多个配置的事情错了?

我也尝试过以下方法:

'use strict';

/* App Module */

var phonecatApp = angular.module('phonecatApp', [
  'ngRoute', …
Run Code Online (Sandbox Code Playgroud)

javascript angularjs chromium-embedded

4
推荐指数
1
解决办法
9917
查看次数

标签 统计

angularjs ×1

chromium-embedded ×1

javascript ×1