【问题标题】:using angularjs to build iframe url使用 angularjs 构建 iframe url
【发布时间】:2017-04-14 02:46:30
【问题描述】:

我从我想要动态的 url 获取 iframe 图像。所以...例如,我想为我正在预览的每个应用程序传递一个不同的 url。

我尝试使用 ng-src 生成我的网址,但似乎失败了。

html:

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

控制器:

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

收到此错误: angular.js:11706 错误:[$interpolate:noconcat] 插值时出错

有什么想法吗?

【问题讨论】:

    标签: angularjs iframe src


    【解决方案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);
    });
    

    【讨论】:

      猜你喜欢
      • 2015-01-15
      • 2016-11-16
      • 1970-01-01
      • 2021-07-18
      • 2017-12-15
      • 2014-07-08
      • 1970-01-01
      • 2018-05-19
      • 1970-01-01
      相关资源
      最近更新 更多