【问题标题】:cannot load file in iframe getting error: Can't interpolate: {{file}}无法在 iframe 中加载文件出现错误:无法插值:{{file}}
【发布时间】:2016-07-04 07:30:41
【问题描述】:

我想在 iFrame 中加载文件 但我遇到了类似

的错误
angular.js:13642 Error: [$interpolate:interr] Can't interpolate: {{file}}
Error: [$sce:insecurl] Blocked loading resource from url not allowed by $sceDelegate policy.  URL: http://localhost:4000/api/uploads/574ed76718153dac202679b9_resume.pdf

为此,我找到了在控制器中使用以下代码的解决方案

$scope.trustSrc = function(src) {
        return $sce.trustAsResourceUrl(src);
    }

但我在这里面临的问题是 它像非终止循环一样继续执行,并且文件也没有被加载。

这是我的html

<div ng-class="{'col-xs-6': myVar=='something'}">
<div class="panel panel-default panel-height" ng-repeat="candidateInfo in aCandidateDetails track by $index" ng-click="fnInterviewView(candidateInfo.name)">
    <div class="panel-heading header-background">
        <div stop-watch time="xyz" name="candidateInfo.name" time-of-interview="candidateInfo.doi" class="stop-watch"></div>
        <div class="row">
            <div class="col-xs-2"><a style="cursor:pointer" class="pull-right">{{candidateInfo.name}}</a></div>
            <div class="col-xs-offset-9"><a  style="cursor:pointer" ng-click="fnVar(candidateInfo.name,candidateInfo.filepath);$event.stopPropagation()" data-toggle="collapse" data-target="{{'#'+toggle}}">{{candidateInfo.name}} resume</a></div>
        </div>
    </div>
</div>

angular.module('hrPortalApp')
.controller('candidateInterviewCtrl', function($scope, $state, $sce, getCandidateInterviewListService) {
    getCandidateInterviewListService.fnGetCandidateDetails(name).then(function(response) {
        $scope.aCandidateDetails = response;
        console.log(response);
        $scope.toggle = "accor"
    });
    $scope.fnVar = function(name, filepath) {
        $scope.file = "http://localhost:4000/" + filepath;
        $scope.checkVar = !$scope.checkVar;
        if ($scope.checkVar) {
            $scope.myVar = "something";
        } else {
            $scope.myVar = false;
        }
    };
    $scope.fnInterviewView = function(name) {
        $state.go('main.Topics', {
            "candidateDetails": $scope.aCandidateDetails,
            "name": name
        })
    };
    $scope.trustSrc = function(src) {
        return $sce.trustAsResourceUrl(src);
    }

});

我不知道我哪里出错了

任何帮助将不胜感激

【问题讨论】:

  • 您的 iframe 是否在 html 中的其他位置?此外,您包含的 html 比关闭多了一个
    标签,可能缩进关闭了?
  • 我已经关闭了所有 div,并且我的 iframe 也包含在其中,因为我只需要加载我给 src 作为文件路径的文件
  • 也许我遗漏了一些东西,但
    div 看起来没有关闭,除非它之后的所有内容一个孩子,应该缩进,但在标记的末尾仍然应该有另一个
    ,可能只是不包括在内。
  • 它实际上已关闭,但我猜我没有正确包含@Andrew Clavin
  • 我没有看到你的 iframe 实际在哪里,你在哪里调用 trustSrc?

标签: javascript angularjs iframe


【解决方案1】:

看起来您在单击第一个链接时重新路由到“main.Topics”视图,因为它会传播到 div ng-click 函数。

这可能有助于Using iFrames in AngularJS

【讨论】:

    猜你喜欢
    相关资源
    最近更新 更多
    热门标签