Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

"Referencing the Window in Angular expressions is disallowed!" #4853

Closed
jpillora opened this issue Nov 9, 2013 · 26 comments
Closed

"Referencing the Window in Angular expressions is disallowed!" #4853

jpillora opened this issue Nov 9, 2013 · 26 comments

Comments

@jpillora
Copy link

jpillora commented Nov 9, 2013

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'
@ch000
Copy link

ch000 commented Nov 10, 2013

I guess we should use the $window service.

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

But i'm getting the same error with $window

@petebacondarwin
Copy link
Contributor

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//issues/4853#issuecomment-28153758
.

@jackcviers
Copy link
Contributor

👍 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//issues/4853#issuecomment-28154215
.

@petebacondarwin
Copy link
Contributor

Something like this

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

@w3apps
Copy link
Contributor

w3apps commented Nov 14, 2013

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

@jpillora
Copy link
Author

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//issues/4853#issuecomment-28491586
.

@YourDeveloperFriend
Copy link

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

@umbrella-mikhail-menshinskiy

+1 @w3apps thank you so much!

@fredchu
Copy link

fredchu commented Apr 11, 2014

+1 @w3apps thank you!

@andrewboni
Copy link

+1 @w3apps thanks, that solved my issue.

@dlin-me
Copy link

dlin-me commented Jun 20, 2014

awesome. thanks

@bengarvey
Copy link

+1 w3apps

@musketyr
Copy link

👍 @w3apps

@umate
Copy link

umate commented Aug 7, 2014

@w3apps thx for the help!

@svdmitrij
Copy link

+1 @w3apps thank you!

@tarun1793
Copy link

+1 Thanks! @w3apps

@xtang
Copy link

xtang commented Oct 17, 2014

+1 @w3apps

@KynoYang
Copy link

KynoYang commented Nov 4, 2014

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

@KynoYang
Copy link

KynoYang commented Nov 4, 2014

+1 Thanks! @w3apps

@jvannistelrooy
Copy link

+1 @w3apps

@ghost
Copy link

ghost commented Mar 4, 2015

The anwser of @w3apps was enough for me.

@imdreamrunner
Copy link

+1 @w3apps

@SergeyBukhman
Copy link

Looking for an upvote on @w3apps answer, then remember I'm not on stackoverflow :)

@ghost
Copy link

ghost commented Dec 15, 2015

Looking for an upvote on @SergeyBukhman comment, then remembering I'm not on stackoverflow ...

@angular angular locked and limited conversation to collaborators Dec 15, 2015
@petebacondarwin
Copy link
Contributor

Thanks for all the upvotes on #4853 (comment) but I am locking this conversation as all these extra comments are actually diluting the ability to get access to that help.

I will add something to the API docs to cover this issue.

@petebacondarwin
Copy link
Contributor

Added here 05d3ed0

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests