angularjs 中的iframe 标签 ng-src 路径

如果直接写路径到iframe标签里的ng-src中会出现报错;

  解决方法:

1、ng里面有个属性是专门用来解决跨域问题的 $sce。

  用法:

$scope.someUrl = $sce.trustAsResourceUrl('路径');
例:
<ul class="nav nav-tabs" ng-repeat="item in [1,2,3,4]">  
         <iframe ng-src="{{someUrl}}" height="100%" width="100%"></iframe>                    
</ul>

2、可以巧用上面方法写一个过滤器。
angular.module('filters-module', [])
.filter('trustAsResourceUrl', ['$sce', function($sce) {
    return function(val) {
        return $sce.trustAsResourceUrl(val);
    };
}])
例:

<ul class="nav nav-tabs" ng-repeat="item in [1,2,3,4]">  
         <iframe ng-src="{{someUrl |trustAsResourceUrl }}" height="100%" width="100%"></iframe>                    
</ul>
 





 
“我相当乐意花一天的时间通过编程把一个任务实现自动化,除非这个任务手动只需要10秒钟就能完成”
原文地址:https://www.cnblogs.com/flxy-1028/p/6206528.html