angularjs - Exception when exposing $window.print on angular scope -


i'm exposing $window.print() on scope so:

$scope.print = $window.print; 

however, results in exception:

angular.js:13642 exception message: illegal invocation

i need call print thru separate function, make work:

$scope.print = printfn; function printfn() { $window.print(); } 

any ideas why can't use first alternative? running angular 1.5.5

it safe assume every object method depends on this unless proven otherwise, method should bound context before assigned object's method.

window.print native method, in chrome throws illegal invocation instead of complaining on inappropriate this context.

instead of wrapper function, may be

$scope.print = $window.print.bind($window); 

or

$scope.print = angular.bind($window, $window.print); 

Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -