this simple angular controller:
var WorldCtrl = function ($scope) {
$scope.population = 7000;
$scope.countries = [{name: 'India', population: 121}, {name: 'China', population: 178} ];
};
And this controller gets used in this way inside the views
<body ng-app>
<ul ng-controller="WorldCtrl">
<li ng-repeat="country in countries">
{{country.name}} has population of {{country.population}}
</li>
<hr>
World's population: {{population}} millions
</ul>
</body>
Question
- Is
WorldCtrl
is a plan-old javascript function object OR there is more to it? - Nowhere in the code, there is line which invokes
WorldCtrl()
function. how does that happen? $scope
appear to be parameter/argument passed ontoWorldCtrl()
but it doesn't behave that way. Because it was a normal argument, we could have called it WorldCtrl(foo) and it would still work the same. But$scope
seems sensitive to naming & only works when WorldCtrl($scope) is defined. Anyone explain this why?$scope
seems like an object that angular creates on its own & is passed-by reference asWorldCtrl
function doesn't return anything useful. so any changes to $scope change the original object which angular then passes into the views. correct?