0

I have an html view which is full of angular directives. The problem is that each directive performs a lot of http requests. This is causing heavy load on the CPU usage. Our idea was to load one directive at a time i.e. as one directive initializes its controller (and therefore performs the calls), the next one starts.

EDIT: The directives are in different DOM elements i.e. I can't use priorities or preLinks, etc..

Do you think this is even possible? Thanks.

Bernice
  • 2,552
  • 11
  • 42
  • 74
  • possible duplicate of [What is \`priority\` of ng-repeat directive can you change it?](http://stackoverflow.com/questions/19270392/what-is-priority-of-ng-repeat-directive-can-you-change-it) – Vineet Jul 16 '15 at 11:17
  • @Vineet maybe... but does this mean that if directive 1 has priority of 1001 and directive 2 has priority of 1002 that directive 2 has finished all of its calls before directive 1 is called? – Bernice Jul 16 '15 at 11:23
  • Priority will work for single DOM element, I think in this case directive are on different DOM element, Is it right @Bernice? – Kishor Sharma Jul 16 '15 at 11:26
  • yes I have multiple directives defined in different DOM elements.. So to use priority directives have to be in a parent-child hierarchy @KishorSharma? – Bernice Jul 16 '15 at 11:27
  • just to clarify, I want a way for the user to use these directives as widgets. i.e. the user can have as many widgets as he wants in a page. But at the same time I need to monitor the flow of directives execution because of the large number of queries being executed (performance issues) – Bernice Jul 16 '15 at 11:29
  • @Bernice. Oops then in your case above hint will not work. – Vineet Jul 16 '15 at 11:31
  • @Bernice, You can have a widgetRequestService and each directive will use it to make request. In service, you can stackup and process each request. – Kishor Sharma Jul 16 '15 at 11:38
  • @KishorSharma could you please clarify your comment? Are you talking about some kind of lock / queue? – Bernice Jul 16 '15 at 11:44

1 Answers1

0

In my opinion you can have a WidgetRequestService, which can be used by widget to make http request. You directive can make request like:

widgetRequestService.makeCall(url, priority, function() {/*success call back*/}, function () {/*failcallBack*/})

And in your service you can have a queue (you can sort it based on priority after every call) and a method:

makeCall: function (url, priority, successCallback, failCallback) {
    //add url to queue
} 

processCall: function() {//to process url}

This way you widget will provide its priority set by user.

Kishor Sharma
  • 599
  • 8
  • 15