cannot load file in iframe getting error: Can't interpol

cannot load file in iframe getting error: Can't interpolate: {{file}}

本文关键字:Can interpol error file load in iframe getting cannot      更新时间:2023-09-26

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

我不知道哪里出了问题

如有任何帮助,不胜感激

看起来您正在重路由到'main '。当它传播到div -click函数时,点击第一个链接的主题视图。

这可能有助于在AngularJS中使用iframe