$window 角度.js在使用 $window.open 时引发异常

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

本文关键字:window 异常 open 角度 js      更新时间:2023-09-26

我得到这个错误:

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

当我尝试在angularjs中使用$window.open/window.open时。

生成.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;

这是我使用过的代码。我需要做什么来避免每次使用 $window.open 时引发此错误?

您正在从视图中运行$window.open()。请改为这样做:(不要使用返回)

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