无法在iframe中加载文件获取错误:无法插入:{{file}}

时间:2016-07-04 07:30:42

标签: javascript angularjs iframe

我想在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);
    }

});

我不知道我哪里出错了

任何帮助将不胜感激

1 个答案:

答案 0 :(得分:0)

看起来你正在重新路由到主要的.Topics&#39;单击该第一个链接时的视图,因为它传播到div-click功能。

这可能会有助Using iFrames in AngularJS