Javascript angular.js中的$window在使用$window.open时引发异常
我将抛出此错误:Javascript angular.js中的$window在使用$window.open时引发异常,javascript,angularjs,Javascript,Angularjs,我将抛出此错误: Error: Error: [$parse:isecwindow] Referencing the Window in Angular expressions is disallowed! 当我尝试在angularjs中使用$window.open/window.open时 Generate.html <div class="print-report-footer" ng-show="vm.clicked"> <button type="button
Error: Error: [$parse:isecwindow] Referencing the Window in Angular expressions is disallowed!
当我尝试在angularjs中使用$window.open/window.open时
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>
这是我使用的代码。我需要做什么来避免每次使用$window.open时抛出此错误?您正在从视图中运行$window.open()。改为:(不使用return)
您正在从视图中运行$window.open()。改为:(不使用return)
你能试试$window.open(路径);返回;看起来您正在从视图调用该函数,这是导致问题的原因。您确定错误是在$window而不是其他位置抛出的吗?如果
此
被初始化为窗口
@MaximShoustin窗口
不可测试,则可能存在范围问题,$window
可以将问题中的代码拆分为单独的部分,以确定它们所在的文件。目前,您的downloadFile
函数似乎不是控制器的一部分。鉴于您正在使用控制器作为语法,它至少应该是this.downloadFile=function…
Plunker demo here~。这是return
语句,您可以试试$window.open(path);返回;看起来您正在从视图调用该函数,这是导致问题的原因。您确定错误是在$window而不是其他位置抛出的吗?如果此
被初始化为窗口
@MaximShoustin窗口
不可测试,则可能存在范围问题,$window
可以将问题中的代码拆分为单独的部分,以确定它们所在的文件。目前,您的downloadFile
函数似乎不是控制器的一部分。鉴于您正在使用控制器作为语法,它至少应该是this.downloadFile=function…
Plunker demo here~。是return
语句导致了error@Phil我知道这个问题已经解决了,但你们能解释一下为什么return语句会导致这个错误吗?你们返回的是$window.open()函数,它是从html模板视图运行的。虽然可以从文档中访问窗口,但在本例中无法从视图中访问它。导致此问题的肯定是返回的error@Phil我知道这个问题已经解决了,但你们能解释一下为什么return语句会导致这个错误吗?你们返回了$window.open()函数,正在从html模板视图运行的。虽然可以从文档访问窗口,但在这种情况下,无法从视图访问窗口。
function downloadFile ( fileType ) {
var path = '/images/reports/DistrictSchoolReport.' + fileType;
return $window.open( path );
}
self.downloadFile = downloadFile;
function downloadFile ( fileType ) {
var path = '/images/reports/DistrictSchoolReport.' + fileType;
$window.open( path );
}