I'm reading Pro AngularJS by Adam Freeman, and I have a nitpicky question concerning one of the book's examples:
myApp.controller("tomorrowCtrl", function($scope) {
var dayNames = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday";]
$scope.day = dayNames[(new Date().getDay() + 1) % 7];
});
I understand what this controller's overall purpose is: to show the name of the day of the week on the view via $scope.day. But I'm confused about why the controller is using an ordinary Javascript array - var dayNames - to create the $scope object.
The AngularJS controller documentation explains that controllers are used to:
set up the initial state of the $scope object [and to] add behavior to the $scope object.
And sure enough, dayNames helps set up the initial state of the $scope object. It also contains a bit of the application's business logic, so I guess it sort of checks out. My worry is that I haven't found any other examples of AngularJS controllers that follow this design pattern; I haven't found anything in the Angular controller docs, nor the PhoneCat tutorial.
Does it make sense to include ordinary Javascript objects in AngularJS controllers like this? (Is this considered harmless?)
If not, why? Are there any good reasons to not include ordinary Javascript objects in controllers? Also, is there a different way that dayNames should fit into the Angular schema, like a directive or a service?