• Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

Angularjs Events

Joined
May 27, 2008
Messages
3,577 (1.02/day)
Likes
533
Location
Huddersfield, uk
Processor E8200
Motherboard Asus P5KC
Cooling cooler master hyper tx3, 2x 120mm, 1x 80mm
Memory 4 GB DDR3 OCZ Black Edition
Video Card(s) Gigabyte HD 2600xt silent pipe II
Storage 500GB WD Sata / 60 GB Samsung IDE
Display(s) 20" samusng LCD, gaming at 1680 x 1050
Case some old amd thing
Audio Device(s) onboard
Power Supply 650W
Software Windows 8.1, with 'start is back' obviously
Benchmark Scores It boots whilst im still young so im pleased with that.
#1
Ive created a single page application using nodeJs and angularJS. All my script files are loaded when the page is first loaded. My views are dynamically loaded using ng-view.

This means that my controllers for all the different pages are instantiated even when the view for that page isn't loaded. Whilst this isn't a problem, may even make viewing the app better not having to wait for angular to bootstrap things up. I do have a problem with events that are being fired in my services.

I have some RTI (Real Time Information, think I used to right abbreviations) pushing data periodically from the server which is then broadcast across my app using angularJS's $broadcast. Trouble is as my controllers are always instantiated there event listeners are firing when my service broadcasts. Even when the view is not loaded for them.

Is there a way to stop this? It's not really a problem, and i could always look into lazy-loading i think its called of controllers. However i can see possible problems and was just wondering if there's a quick and easy solution to stop an event listener firing when the controllers corresponding view is not loaded.