Saravanan
Saravanan

Reputation: 1237

Using window in AngularJS to access iframe contents

I have a iframe which return some json string. I have to use that json to construct a table.

<iframe id="idHiddenFrame" name="HiddenFrame" src="/PTO/PlattsIncident.nsf/frmBlank?ReadForm" width="0px" height="0px" onload="addAttachment()"></iframe>

Below is the javascript code using angular js

$window.addAttachment=function(){
        if($.parseJSON(frames["HiddenFrame"].document.getElementsByTagName("body")[0].innerHTML)!=null){
            $scope.attachments.push($.parseJSON(frames["HiddenFrame"].document.getElementsByTagName("body")[0].innerHTML));
            console.log($scope.attachments);
        }
    }

console.log is printing the correct value as below

0: Object
attachName: "Root Cause Analysis - Stringer SSF - 02072013.doc"
docID: "290005B6A4CFB9FD85257BBB002433A8"

But below code using ng-repeat is not working

<ul class="list-group">
    <li class="list-group-item" ng-repeat="attachment in attachments">{{attachment.attachName}}</li>
</ul>

Any help is much appreciated.

Upvotes: 1

Views: 2807

Answers (1)

JQuery Guru
JQuery Guru

Reputation: 6963

Can you try below code and used $scope.$apply():

$window.addAttachment=function(){
        if($.parseJSON(frames["HiddenFrame"].document.getElementsByTagName("body")[0].innerHTML)!=null){
            $scope.attachments.push($.parseJSON(frames["HiddenFrame"].document.getElementsByTagName("body")[0].innerHTML));
            console.log($scope.attachments);
           $scope.$apply();
        }
    }

Upvotes: 2

Related Questions