如何使用Angularjs中的本地存储本地存储文件路径?

时间:2016-09-14 08:03:24

标签: angularjs iframe

我尝试$localstorage在本地存储文件路径并使用iframe预览文件,但我收到错误。

$scope.getResume = function() {

            var resumeJson = {
                    "json":{
                        "request":{
                            "candidateid":$rootScope.globals.currentUser.userId,
                            "type":2
                        }
                    }
               };


    var getresume = "http://MyServerURL?request=" + JSON.stringify(resumeJson);

    $scope.resume = $localStorage.$default({x: getresume});
}

HTML:

<iframe id="resume" src="{{resume.x}}" style="margin-top: 2em; height: 100%; width: 100%;"></iframe>

但我收到错误并在框架内显示错误消息:

  

不能获得/%7B%22json%22:%7B%22request%22:%7B%22candidateid%22:44,%22type%22:2%7D%7D%7D

当我尝试检查页面时,我发现iframe src = "{"json":{"request":{"candidateid":44,"type":2}}}"而不是我的网址。

1 个答案:

答案 0 :(得分:0)

看,我为你写了一个Plunker。它是动态设置iFrame src的100%工作解决方案。

https://plnkr.co/edit/tpl:CR2TtS1zz9wFGgsl5z2c?p=preview

也许您应该将src更改为ng-src

<iFrame ng-src="{{mc.resume}}"></iFrame>