I am a newbie to Angular, I came across this fiddle which explains how nested controller works. When I rename $scope to something else say $abc and it doesn't work, does it mean that $scope is a reserved keyword in angularJS?
function CarController($scope) {
$scope.name = 'Car';
$scope.type = 'Car';
}
function BMWController($scope) {
$scope.name = 'BMW';
}
function BMWMotorcycleController($scope) {
$scope.name = 'BMWMotorade';
$scope.type = 'Motorcycle';
}
Effectively, yes. It's not a reserved word in the sense that e.g. if and while are but AngularJS gives it meaning. In your example Angular parses the string representation of the function and uses the named parameters to determine what to "inject" into the function when it calls it.
In this case you're injecting the $scope service.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With