I've been reading the ng-book and just worked through the Code School Angular course the other day and am confused about when to use $scope in a controller and when to use an attribute of the controller.
In the code school course, the controllers were setup like this:
app.controller('LibraryController', function(){
this.books = getBooks //some function that gets an array
});
But in the ng-book and elsewhere, I've only seen this done as a scope:
app.controller('LibraryController', function($scope){
$scope.books = getBooks //some function that gets an array
})
From what I can tell, these two approaches are exactly the same. The first is used in the view like this:
<div ng-controller="LibraryController as libraryCtrl">
<ul>
<li ng-repeat="book in libraryCtrl.books">
While the second would be
<div ng-controller="LibraryController">
<ul>
<li ng-repeat="book in books">
Am I not understanding something fundamental here? Is there a difference in these two approaches and why is the $scope approach used almost exclusively?