2016-11-29 72 views
1

我從我想要的動態url獲取iframe圖像。所以...例如,我想爲每個應用程序#傳遞一個不同的URL,我正在預覽。使用angularjs構建iframe url

我試過使用ng-src來生成我的url,但它似乎失敗了。

HTML:

<iframe ng-src="http://localhost:3000/v4/{{applicationNumberText}}/{{documentIdentifier}}"></iframe> 

控制器:

$scope.applicationNumberText = '09123456'; 
$scope.documentIdentifier = 'E1DUJW9JPP1GUI3'; 

收到此錯誤: angular.js:11706錯誤:[$插值:noconcat]錯誤而插值

什麼想法?

回答

1

那麼,對於一個你不能連接像這樣的字符串。其次,你將需要使用$sce並告訴你的應用程序它是一個可信的url資源。看到小提琴:https://jsfiddle.net/ojzdxpt1/4/

app.controller('TestController', function($scope,$sce) { 
    $scope.applicationNumberText = '09123456'; 
    $scope.documentIdentifier = 'E1DUJW9JPP1GUI3'; 
    $scope.iFrameUrl = $sce.trustAsResourceUrl("http://localhost:3000/v4/" + $scope.applicationNumberText + "/" + $scope.documentIdentifier); 
}); 
+0

正是我所需要的非常感謝! – jeremy