Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS controller $scope reserved keyword?

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';

}
like image 502
Kaizar Laxmidhar Avatar asked Sep 25 '26 16:09

Kaizar Laxmidhar


1 Answers

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.

like image 126
James Allardice Avatar answered Sep 28 '26 06:09

James Allardice