Ela*_*oty 12 html javascript iframe controller angularjs
使用AngularJS,我试图将"myLink"URL地址加载到另一个html中的iframe.data.No是我从另一个地方拉出来并且工作正常的ID(获取我需要的网址的ID)
在控制器中 - "TransactionsCtrl":
$scope.myLink = "http://"the real url"+ data.No +"&file="+ data.No +"&contract_id="+ data.No;
console.log($scope.myLink);
Run Code Online (Sandbox Code Playgroud)
在HTML中:
<div ng-controller= "TransactionsCtrl">
<iframe ng-src="{{myLink}}"></iframe>
</div>
Run Code Online (Sandbox Code Playgroud)
我得到的就是这个:
Error: [$interpolate:interr] Can't interpolate: {{myLink}}
Error: [$sce:insecurl] Blocked loading resource from url not allowed by $sceDelegate policy. URL
Run Code Online (Sandbox Code Playgroud)
当我硬编码网址工作正常.
Mic*_*ael 23
在控制器中你应该使用:
$scope.myLink = $sce.trustAsResourceUrl(myUrl)
Run Code Online (Sandbox Code Playgroud)
它适用于我:你可以在js代码中将其写为函数
$scope.trustSrc = function(src) {
return $sce.trustAsResourceUrl(src);
}
$scope.iframe = {src:"http://www.youtube.com/embed/Lx7ycjC8qjE"};
Run Code Online (Sandbox Code Playgroud)
并在您的视图中使用它:
<iframe ng-src="{{trustSrc(iframe.src)}}"></iframe>
Run Code Online (Sandbox Code Playgroud)
或者你可以把它写成过滤器,如:
.filter('trusted', function($sce){
return function(url) {
return $sce.trustAsResourceUrl(url);
};
Run Code Online (Sandbox Code Playgroud)
})
并在视图中使用它:
<iframe ng-src="{{iframe.src | trusted}}"></iframe>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6965 次 |
| 最近记录: |