angularJS插入html及更換iframe的src


html:

ng-bind-html


<div class="tabs_content" ng-bind-html="specialHtml"></div>

ng-src

<iframe id="iframe-projects" onload="set(this)" ng-src="{{trustSrc}}" frameborder="0"></iframe>

加載模塊:

ng-bind-html


angular.module('DLPortalApp', []).controller("MyCtrl", function ($scope, $http, $sce) { //重點列表項目 $scope.specialHtml = $sce.trustAsHtml('<iframe id="iframe-projects" onload="set(this)" src="你的地址" frameborder="0"></iframe>'); });

/*重點:
$sce這個參數,它相當於一把鑰匙
*/

ng-src

angular.module('DLPortalApp', []).controller("MyCtrl", function ($scope, $http, $sce) {
    
    //重點列表項目
    $scope.trustSrc = $sce.trustAs($sce.RESOURCE_URL,"你的地址");
//$scope.trustSrc = $sce.trustAsResourceUrl("你的地址");//等同於這個方法 });

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM