In my own experience, I actually prefer the expression style whenever
possible, but that's due to separation of code. I'm not wild about
cluttering up my scope with one-off, difficult-to-find logic code. If an
expression is used multiple times for the same semantic purpose, I'd
consider putting it into the controller (change it in only one place). But
if the expression is used in just the one place, you can see just what it
does and how it works by examining only the HTML file, and you don't have
to wonder if 'shouldFireEvent()' has been updated to reflect the new state
of scope variables when you change some logic or other layout stuff.

Also, and this is my particular environment: I'm working with an HTML dev
who is savvy enough to write expression code in the template files, but I
don't want this person to be writing straight-up controller code, so having
these kinds of expressions handled solely in the view layer keeps things
nicely organized.

eric

On Wed, Sep 17, 2014 at 7:53 AM, ganaraj P R <[email protected]> wrote:

> Hi Sander,
>
> You are right. There are two sides to this. 1) The number of times the
> iteration runs. The other is the number of watchers currently in effect.
> The important consideration comes in when you have loads of watchers.
>
> The problem is that the function style is much more elegant to read. The
> expression style makes the templates look ugly ( and badly designed! ). The
> expression style is cheaper (watchers dont fire unless they need to! )
> while the function style is slightly costlier ( runs atleast once every
> digest cycle ).
>
> On Wed, Sep 17, 2014 at 3:17 PM, Sander Elias <[email protected]>
> wrote:
>
>> Hi Ganaraj,
>>>
>>>
>> The size of the application has little to do with it. It is the number of
>> iterations on that single piece of code that might be affected.
>>
>> You should know that there will be very little difference. Expressions
>> are parsed, not piped trough eval/new Function construction.
>> Even if you put in a function in the expression, it will be parsed
>> anyway. My guess is that function will often be slower, because of the extra
>> look-up. However I think you have to run at least 100.000 iterations to
>> get a measurable difference.
>> If you need that amount of iterations in your view, you have bigger
>> problems ;)
>>
>> 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.
>>
>
>
>
> --
> Regards,
> Ganaraj P R
>
> --
> 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