Currently, I am analyzing an example in CodeSchool's "Staying Sharp with Angular" course in section 1.5. Here is the code snippet:
angular.module('NoteWrangler')
.controller('NotesIndexController', function($http) {
var controller = this;
$http({method: 'GET', url: '/notes'}).success(function(data){
controller.notes = data;
})
});
I have gone through Mozilla's developer network guide related to [this][1], but my comprehension is still not optimal.
In the line from the above example:
var controller = this;
Why are we assigning controller = this? Why not simply declare var controller;? Is it because by equating it to this, we are making it a global variable rather than just a local one that would only be modified inside the success callback of the controller?
If needed, they later make use of the following in the HTML:
<div class="note-wrapper">
<a class ="card-notes" ng-repeat="notes in indexController.notes">
</a>
</div>