0

I get this error thrown:

Error: Error: [$parse:isecwindow] Referencing the Window in Angular expressions is disallowed!

When I try using $window.open/window.open in angularjs.

Generate.html

<div class="print-report-footer" ng-show="vm.clicked">
    <button type="button" class="btn btn-primary" ng-click="vm.downloadFile('pdf')">PDF</button>
    <button type="button" class="btn btn-primary" ng-click="vm.downloadFile('xls')">XLS</button>
    <button type="button" class="btn btn-primary" ng-click="vm.downloadFile('csv')">CSV</button>
</div>

Generate.ctrl.js

    function downloadFile ( fileType ) {
        var path = '/images/reports/DistrictSchoolReport.' + fileType;
        return $window.open( path );
    }

    self.downloadFile   = downloadFile;

This is the code that I have used. What do I need to do to avoid this error thrown everytime I use $window.open?

7
  • can you try $window.open(path); return; Looks like you are calling that function from the view, which is causing the problem. Commented Jun 18, 2015 at 22:55
  • 1
    Are you sure the error is being throwing at $window not elsewhere? You could have scoping issue where this is being initialized as window. Commented Jun 18, 2015 at 22:56
  • 1
    @MaximShoustin window isn't testable, $window is Commented Jun 18, 2015 at 23:21
  • 1
    Can you split the code in your question into separate parts identifying which file they're in. At the moment, it doesn't look like your downloadFile function is part of a controller. Seeing as you're using the controller as syntax, it should at least be this.downloadFile = function... Commented Jun 18, 2015 at 23:23
  • 1
    Plunker demo here ~ plnkr.co/edit/cQdQiPJg0P0Z2wChSNKk?p=preview. It's the return statement Commented Jun 19, 2015 at 0:25

1 Answer 1

5

You are running $window.open() from the view. Do this instead: (don't use return)

function downloadFile ( fileType ) {
    var path = '/images/reports/DistrictSchoolReport.' + fileType;
    $window.open( path );
}
Sign up to request clarification or add additional context in comments.

3 Comments

It's definitely the return that's causing the error
@Phil i know this problem is solved, but can you guys explain to me why the return statement causes this error?
you were returning the $window.open() function, which was being run from the html template view. Although window is accessible from the document, it's not accessible from the view in this case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.