--
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 angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.
Hi Łukasz,
- does either of the solutions hides some bugs or flaws?
No, it’s basically exactly the same thing. However, I think the second approach might confuse you. let me explain.
you decide to do some assigning in your controller, like setting the selectedUserIs so you do in your controller:selectedUserId = fetchAUser();. This will not update $scope.model.selectUserId. You have to remember that
JavaScript primitives, are never passed by reference.
- is the overhead of watching the scope is higher/lower in any case (performance implications)?
No. As I said, it is exactly the same thing. there is no difference in the $scope. All that you have done is
put some extra visual clues in your code. with exception of the primitives as mentioned above. those will
consume some extra memory (the extra reference to the array will do to, but this is such a small amount,
you can safely ignore that)
- is there any recommended way of doing this?
Your first way is the recommend way if you still want to use $scope. The current recommend way is to
use the controllerAs syntax, in where the $scope inheritance is mostly mitigated.
I created a sample plunk here, that I created for someone that needed localized events. There are a
couple of controllers in there that follow the new recommend way.
When you have any questions left, don’t’ hesitate to ask!
Regards
Sander
--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/zAjgjeyWptI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
hi Łukasz,
Nope, no speed difference. If you are putting in information pro reference, it’s just that. 2 pointers to the same data.
There is some documentation and recorded talk in where the core team hints the controllerAs syntax is from now on the
preferred way to do things. But as I see it, they are nudging us that direction, not pushing.
So it boils down to your preferences.
In the controllerAs, an dot in your data is less important. There is no technical reason anymore for the dot rule
(well, kind off, that happens technically is that this gets put on the scope automatically. so, $scope.controlleAsName is
available on the scope hierarchy)
I think it still is a good plan to put your models in their own object, and attach that to the this.
Does this all make sense to you?
Regards
Sander
--