One problem is - does the doSomething() take a long time? Hard to say from
looking at it, but if you put that call in a click handler and it does take
a long time to resolve, you'll be blocking execution Everywhere Else on the
page (single-threaded and all). That's generally a good reason to put
things in a $timeout, IMO.

It's worth noting that $timeout is better to use here than setTimeout, as
it wraps the timed-out call in a scope.apply to make sure that angular is
notified of any changes you make to models inside that call.

That said, in general I've not had issues with calling functions passed in
to a directive using & parameters. Sander's also right - if you need a
digest cycle to run in there, you need to release control of the thread and
let angular do its thing. Cooperative multitasking, basically.


On Sun, May 25, 2014 at 11:38 PM, Sander Elias <[email protected]>wrote:

> Hi Larion,
>
> You are right, it is just javascript. AngularJS is also javascript, so it
> can't run a digest cycle between 2 statements is it?
> example in a directive I do:
>
> ```javascript
>  scope.model = 'blah'; // model is bound to something else way up in the
> hierarchy.
>  // here is no time for angular to run anything! no way for it to update
> anything!
>  scope.doSomething(); // doSomething is also way up in the hierarchy  but
> on an other place then model..
> ```
> It is not only javascript that suffers from this. All code that runs in a
> single thread in any language will have the same issue.
>
> Regards
> Sander
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "AngularJS" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/angular.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to