angular.js icon indicating copy to clipboard operation
angular.js copied to clipboard

"Referencing the Window in Angular expressions is disallowed!"

Open jpillora opened this issue 13 years ago • 26 comments

How do we do a window.open now?

Error: [$parse:isecwindow] Referencing the Window in Angular expressions is disallowed! Expression: foo()
  scope.foo = ->
    window.open 'https://example.com'

jpillora avatar Nov 09 '13 09:11 jpillora

I guess we should use the $window service.

http://docs.angularjs.org/api/ng.$window

But i'm getting the same error with $window

ch000 avatar Nov 10 '13 16:11 ch000

Put it in a controller function that you call from the expression in the template. Angular templates should not contain code like this directly On 10 Nov 2013 16:17, "Christian" [email protected] wrote:

I guess we should use the $window service.

http://docs.angularjs.org/api/ng.$window

But i'm getting the same error with $window

— Reply to this email directly or view it on GitHubhttps://github.com/angular/angular.js/issues/4853#issuecomment-28153758 .

petebacondarwin avatar Nov 10 '13 16:11 petebacondarwin

:+1: For keeping calls like that out of a template.

On Sun, Nov 10, 2013 at 10:40 AM, Pete Bacon Darwin < [email protected]> wrote:

Put it in a controller function that you call from the expression in the template. Angular templates should not contain code like this directly On 10 Nov 2013 16:17, "Christian" [email protected] wrote:

I guess we should use the $window service.

http://docs.angularjs.org/api/ng.$window

But i'm getting the same error with $window

— Reply to this email directly or view it on GitHub< https://github.com/angular/angular.js/issues/4853#issuecomment-28153758> .

— Reply to this email directly or view it on GitHubhttps://github.com/angular/angular.js/issues/4853#issuecomment-28154215 .

jackcviers avatar Nov 10 '13 17:11 jackcviers

Something like this

myMod.controller('MyCtrl', function($scope, $window) {
  $scope.OpenWindow = function(...) {
    $window.open(...);
  };
});

petebacondarwin avatar Nov 10 '13 18:11 petebacondarwin

If you are using coffeescript it's a problem caused by coffeescript habit of returning everything and in your case returns a "dom" object. Try something like:

scope.foo = -> window.open 'https://example.com' return true

w3apps avatar Nov 14 '13 15:11 w3apps

Ahh that's it, I did solve it but I couldn't figure out why, thanks

On Friday, November 15, 2013, Adrian-Catalin Neatu wrote:

If you are using coffeescript it's a problem caused by coffeescript habit of returning everything and in your case returns a "dom" object. Try something like:

scope.foo = -> window.open 'https://example.com' return true

— Reply to this email directly or view it on GitHubhttps://github.com/angular/angular.js/issues/4853#issuecomment-28491586 .

jpillora avatar Nov 14 '13 15:11 jpillora

+1 @w3apps that's what I was doing.

YourDeveloperFriend avatar Mar 28 '14 16:03 YourDeveloperFriend

+1 @w3apps thank you so much!

+1 @w3apps thank you!

fredchu avatar Apr 11 '14 06:04 fredchu

+1 @w3apps thanks, that solved my issue.

andrewboni avatar May 30 '14 21:05 andrewboni

awesome. thanks

dlin-me avatar Jun 20 '14 13:06 dlin-me

+1 w3apps

bengarvey avatar Jun 24 '14 21:06 bengarvey

:+1: @w3apps

musketyr avatar Jun 30 '14 12:06 musketyr

@w3apps thx for the help!

umate avatar Aug 07 '14 12:08 umate

+1 @w3apps thank you!

svdmitrij avatar Aug 13 '14 09:08 svdmitrij

+1 Thanks! @w3apps

tarun1793 avatar Sep 07 '14 10:09 tarun1793

+1 @w3apps

xtang avatar Oct 17 '14 08:10 xtang

@xtang 哈哈 我也遇到这个问题了

KynoYang avatar Nov 04 '14 03:11 KynoYang

+1 Thanks! @w3apps

KynoYang avatar Nov 04 '14 03:11 KynoYang

+1 @w3apps

jvannistelrooy avatar Jan 21 '15 09:01 jvannistelrooy