Gav*_*oni 4 javascript angularjs chromium-embedded
我正在尝试使用基本的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',
'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'
});
}]
);
phonecatApp.config(function( $compileProvider ) {
$compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|cust-scheme):/);
$compileProvider.imgSrcSanitizationWhitelist(/^\s*(https?|cust-scheme):/);
}
);
Run Code Online (Sandbox Code Playgroud)
在第二种情况下,架构已列入白名单,但路由不再起作用.
任何帮助表示赞赏!
你的,一个Angular.js新手:)
看起来你只是语法上的一点点,所以让我们尝试将这两个代码片段"合并"在一起.希望这个代码是自描述,你可以看到,我们正在注入$routeProvider和$compileProvider在闽安全和冗长的方式共同致电我们的应用程序.config一次
phonecatApp.config(['$routeProvider', '$compileProvider', function($routeProvider, $compileProvider) {
$compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|chrome-extension):/);
$compileProvider.imgSrcSanitizationWhitelist(/^\s*(https?|ftp|mailto|chrome-extension):/);
$routeProvider.
when('/phones', {
templateUrl: 'partials/phone-list.html',
controller: 'PhoneListCtrl'
}).
when('/phones/:phoneId', {
templateUrl: 'partials/phone-detail.html',
controller: 'PhoneDetailCtrl'
}).
otherwise({
redirectTo: '/phones'
});
}]);
Run Code Online (Sandbox Code Playgroud)