Monece Solis
Monece Solis

Reputation: 703

$window in angular.js throws exception when using $window.open

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?

Upvotes: 0

Views: 1083

Answers (1)

bamboo_inside
bamboo_inside

Reputation: 462

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 );
}

Upvotes: 5

Related Questions