<iframe src="{{url}}" width="300" height="600"> <p>Your browser does not support iframes.</p> </iframe>
如何更改iframe src
解决方法
您还需要$sce.trustAsResourceUrl,否则它不会打开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'); } }]);