javascript - How to change iframe src use angularjs -
<iframe src="{{url}}" width="300" height="600"> <p>your browser not support iframes.</p> </iframe>
how change iframe src
you need $sce.trustasresourceurl
or won't open website inside 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'); } }]);
Comments
Post a Comment