我正在尝试将 Angular 与应用程序列表一起使用,每个应用程序都是一个链接,可以更详细地查看应用程序 (apps/app.id
):
<a id="{{app.id}}" href="apps/{{app.id}}" >{{app.name}}</a>
每次我点击其中一个链接时,Chrome 都会将 URL 显示为
unsafe:chrome-extension://kpbipnfncdpgejhmdneaagc.../apps/app.id
unsafe:
是从哪里来的?
最佳答案
您需要使用正则表达式将 URL 协议(protocol)显式添加到 Angular 的白名单中。默认情况下仅启用 http
、https
、ftp
和 mailto
。当使用诸如 chrome-extension:
之类的协议(protocol)时,Angular 会在未列入白名单的 URL 前加上 unsafe:
。
将 chrome-extension:
协议(protocol)列入白名单的好地方是在模块的配置 block 中:
var app = angular.module( 'myApp', [] )
.config( [
'$compileProvider',
function( $compileProvider )
{
$compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|chrome-extension):/);
// Angular before v1.2 uses $compileProvider.urlSanitizationWhitelist(...)
}
]);
当您需要使用诸如file:
和tel:
之类的协议(protocol)时,同样的过程也适用。
请参阅 AngularJS $compileProvider API documentation了解更多信息。
关于javascript - AngularJS 在扩展页面中将 URL 更改为 "unsafe:",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15606751/