Reputation: 12557
Inside an angular.js controller we could add methods to the scope or to the controller
this.controllerFoo = function(){
};
or
$scope.scopeFoo = function(){
}
When to use what? Currently i add only methods to scope when they are needed inside the view. This feels like good design for me.
but are there any further decissions to make when deciding what to add the method?
Upvotes: 2
Views: 48
Reputation: 654
the better practice is to actually use the the "controller as" syntax (the this.myFunction approach), because it makes your html clearer and shows you exactly which controller you're using when you're invoking a method (it makes the most sense when you have nested controllers).
take a look at Todd Motto's post, it's very informative
Upvotes: 2