How to use an iframe as ngView?

 ̄綄美尐妖づ 提交于 2020-01-06 13:53:28

问题


I've a page called 'index.html' it has left pane with multiple links and right pane which contains iframe.

When I click a link from left pane the page(not external sites or pages) should get load inside iframe.


回答1:


Angular supports ng-src on iframe , so you can set ng-src with your url like this.

<div><iframe  width="640" height="385" ng-src="{{getUrl()}}"> </iframe></div>

The getUrl sanitizes the url before setting it on the iframe. The controller will be as simple as this.

$scope.currentUrl = "http://www.youtube.com/embed/Lx7ycjC8qjE";

  $scope.urls = [
    {
      name:"http://www.youtube.com/embed/Lx7ycjC8qjE"
    },
    {
      name:"http://www.youtube.com/embed/mMxQHmvQ1pA"
    }];

    $scope.setCurrentUrl = function(url)
    {
      $scope.currentUrl = url;
    }

    $scope.getUrl = function()
    {
      console.log($scope.currentUrl);
       return $sce.trustAsResourceUrl($scope.currentUrl);
    }

Here is a sample plnkr.

http://plnkr.co/edit/EVkyH8LuCXcsWUi1xnvV?p=preview



来源:https://stackoverflow.com/questions/30380769/how-to-use-an-iframe-as-ngview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!