As I delve into Angular, there's something that puzzles me. Being a newcomer to Angular, I recall a tutorial where they employed this syntax for applying properties to a controller's scope:
app.controller('someCtrl', function(){
this.variable = "hey!";
});
Initially, everything was smooth as I started building my web app. However, when I attempted to add some socket.io interactivity with my node.js server, things took a turn. In search of tutorials on integrating them, I stumbled upon this alternative syntax:
app.controller('someCtrl', ['$scope', function($scope){
$scope.variable = "hey!";
}]);
Feeling perplexed by the difference, I decided to dig deeper into Angular's resources on dependency injection and scopes. It turns out that this is the standard way of doing things, allowing interaction not just with $rootScope but also other elements necessary for controllers to communicate effectively. But still, I can't quite grasp the distinction between the two approaches. Could it be that the first one serves as a basic introduction to angular, easing newcomers into the realm of scopes and dependency injection?
Appreciate any insights you can provide.