I've been seeing conflicting information on whether a custom controller is instantiated with a "new" keyword or simply applied to the $scope object.
The documentation site says,
Angular applies (in the sense of JavaScript's Function#apply) the controller constructor function to a new Angular scope object, which sets up an initial scope state. This means that Angular never creates instances of the controller type (by invoking the new operator on the controller constructor). Constructors are always applied to an existing scope object.
But it seems like in Angular 1.2, there is an "as"
construct that will rename a controller to something else as in:
<body ng-controller="DemoController as demo">
<tr ng-repeat="student in demo.students">
<td>{{student.name}}</td>
</tr>
</body>
function DemoController() {
this.students = [...]
}
So this makes it seem like a controller is being instantiated using the new
keyword.
Which one is it? Can someone clarify this?