如何使用AngularJS更改iframe src [英] How to change iframe src use angularjs
本文介绍了如何使用AngularJS更改iframe src的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<iframe src="{{url}}" width="300" height="600">
<p>Your browser does not support iframes.</p>
</iframe>
如何更改iframe src
How to change iframe src
推荐答案
您还需要$sce.trustAsResourceUrl
,否则它将无法在iframe中打开网站:
You need also $sce.trustAsResourceUrl
or it won't open the website inside the iframe:
HTML:
<div ng-app="myApp" ng-controller="dummy">
<button ng-click="changeIt()">Change it</button>
<iframe ng-src="{{url}}" width="300" height="600"></iframe>
</div>
JS:
angular.module('myApp', [])
.controller('dummy', ['$scope', '$sce', function ($scope, $sce) {
$scope.url = $sce.trustAsResourceUrl('https://www.angularjs.org');
$scope.changeIt = function () {
$scope.url = $sce.trustAsResourceUrl('https://docs.angularjs.org/tutorial');
}
}]);
这篇关于如何使用AngularJS更改iframe src的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文