【问题标题】:Error: $interpolate:noconcat Multiple Expressions错误:$interpolate:noconcat 多个表达式
【发布时间】:2016-04-27 00:30:24
【问题描述】:

是否可以在 API 生成的ul 列表中添加带有 src 参数的 iframe 链接?

真的是网址集中。我有提供数据的 API,我希望将其显示为带有 iframe 的列表。

我有这个代码模板:

(...)
var getTemplate = function(contentType) {
var  template = '<ul>'
            +'<li ng-repeat="li in item.list" class="[[li.class]]">'
            +'<iframe width="100%" height="300"'
            +'ng-src="https://myserver.com/?id=[[li.mydata]]"'
            +'</iframe>'
            +'</li></ul>';
        return template;
    };
(...)

interpolate 设置为 [[]]

SCE 安全值得信赖

.config(function($sceDelegateProvider) {
  $sceDelegateProvider.resourceUrlWhitelist([
    'self',
    'https://myserver.com/**',
  ])
 })

当添加到模板&lt;h4&gt;[[li.mydata]]&lt;/h4&gt; 时结果可见,但当添加到 iframe ng-src - 失败并出现此错误

https://docs.angularjs.org/error/$interpolate/noconcat?p0=

任何想法或建议如何解决这个问题?

【问题讨论】:

    标签: angularjs templates iframe


    【解决方案1】:

    我解决了一个问题

    (...)
                +'<iframe width="100%" height="300"'
                +'ng-src="[[li.mydata | EmbedUrl ]]"'
    (...)
    

    然后进入ng.js

      .filter('EmbedUrl', function ($sce) {
      return function(uId) {
        return $sce.trustAsResourceUrl('https://example.com/?id=' + uId  );
      };
    

    【讨论】:

      猜你喜欢
      • 2017-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-22
      • 2014-06-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多