Accessing window object in latest Angular 2 vesion

643 views
Skip to first unread message

Patrick L.

unread,
Mar 17, 2017, 2:40:41 PM3/17/17
to Angular and AngularJS discussion

The browser window object was removed from latest Angular 2, Does anybody know how to reference a Window object in the latest Angular?

Sander Elias

unread,
Mar 18, 2017, 4:54:43 AM3/18/17
to Angular and AngularJS discussion
Hi Patrick,

I wasn't aware of a special Angular window object, can you provide me some more conext?

Regards
Sander

Patrick L.

unread,
Mar 18, 2017, 11:10:26 PM3/18/17
to Angular and AngularJS discussion
Hi Sander,

The window object represents an open window in a browser in javascript.
example: window.document.getElementById... ..
It does exist in Angular 2.0. but I cannot find it in angular 2.4.

Thanks,
Patrick

Sander Elias

unread,
Mar 20, 2017, 9:30:33 AM3/20/17
to Angular and AngularJS discussion
Hi Patrick

I know what the window object is. I was not aware that there was a special "handler" for inside Angular. The context I wanted for you, is your use-case, so I could help you with whatever it was you needed.

Regards
Sander

Patrick L.

unread,
Mar 21, 2017, 12:00:26 PM3/21/17
to Angular and AngularJS discussion
Thanks, Sander.

I am using angular 2 to access Microsoft signalr API. I need wrap JQuery to setup channel with signalr.

Since angular 2 is type script, ng build cannot be completed although I have install all types for JQuery and Signalr.


Thanks,
Patrick

Sander Elias

unread,
Mar 21, 2017, 12:58:54 PM3/21/17
to Angular and AngularJS discussion
Hi Patrick.

I just looked into signalr. Implementation should be pretty straight forward.  I would create a wrapper service, that hooks up the signalr stuff with observables.
Typescript is a superset of es2015/6/7, so you can just embed the code you need. Perhaps you need to use some explicit any type so here and there to get rid of some typing issues.

Just make sure you are running in a browser, and make sure your code doesn't get run in any other setting.

Regards
Sander

Patrick L.

unread,
Mar 21, 2017, 4:22:03 PM3/21/17
to Angular and AngularJS discussion
Since I found some examples which are using JQuery to communicate with signalr, I want to find how angular 2 uses JQuery. Based on your advice, I will try angular typescript to see if it works.

Thanks in advance.
Patrick

Sander Elias

unread,
Mar 22, 2017, 1:21:07 AM3/22/17
to Angular and AngularJS discussion
Patrick,

wow, I just checked out the signalr dependencies, it asks for a jquery 1.6 to 1.9 that's pretty ancient. If you are building something new, you might consider to a slightly newer technology. However, I'm not exactly current in the >NET environment, so it just might be the right thing to use!

Regards
Sander

Sander Elias

unread,
Mar 23, 2017, 12:19:33 AM3/23/17
to Angular and AngularJS discussion
Oh BTW, 

You don't need anything special in Angular, you can just load the libs you need. (if it's a CLI project, its enough to npm install them, and add them to the config)

Regards
Sander
Reply all
Reply to author
Forward
0 new messages