Sunday, 18 August 2013

Private variabes in the controller scope

Private variabes in the controller scope

In angular, following the demos, I can define a controller as:
function TodoCtrl($scope) {
$scope.todos = [
{text:'learn angular', done:true},
{text:'build an angular app', done:false},
{text:'empty dishwasher', done:false}];
$scope.oldtodos = [];
var oldtodos2 = [];
...
You'll note that have two oldtodos. One on the $scope and one just just a
local var. I think the later approach is the way to go if you want to
encapsulate this variable - i.e. no-one other than the controller has any
interest in it and the former is good if you want to pass the variable
back to the model
Are my correct?
Thanks

No comments:

Post a Comment