在Angular routeProvider中使用$ sce.trustAsResourceUrl?

时间:2018-01-04 01:23:38

标签: angularjs angular-routing

对于我的路由,我使用的是来自外部源的静态模板。但是,我一直从Angular得到insecureUrl错误。一个解决方案显然是将$sce.trustAsResourceUrl缠绕在它周围。现在,我试图通过以下方式实现:

myapp.config(['$routeProvider', function($routeProvider, $sce) {
    $routeProvider
        .when('/', {
            controller : 'ProductListController',
            templateUrl : $sce.trustAsResourceUrl([my_external_template]),
            reloadOnSearch: false
        })
        .otherwise({ redirectTo : '/' });
}]);

但是,我得到了喷油器错误。有什么帮助吗?

1 个答案:

答案 0 :(得分:0)

myapp.config(['$routeProvider', '$sce', function($routeProvider, $sce) {
    $routeProvider
        .when('/', {
            controller : 'ProductListController',
            templateUrl : $sce.trustAsResourceUrl([my_external_template]),
            reloadOnSearch: false
        })
        .otherwise({ redirectTo : '/' });
}]);

由于您手动执行minsafe语法,因此需要将$ sce添加到注入数组的字符串部分(理想情况下,不要使用插件在构建过程中使用插件添加之前的)< / p>

相关问题