Reputation: 12660
I have a question pertaining to scope around AngularJS and TypeSscript.
I have come into this project halfway through and am getting familiar with TypeScript. Previously I have written all of my AngularJS code directly in JavaScript.
Something unusual happens in the controllers and views of this application. Instead of putting members to be bound in the scope on the $scope object passed into the constructor, it appears that they are placed directly on the Controller class itself, like this:
module Wizard.Controllers {
"use strict";
export class LoginController extends BaseAppealController {
static $inject = ["$q", "$scope"];
private isInForgottenPasswordMode: boolean;
private passwordSent: boolean;
// other properties
private scope;
constructor($q: angular.IQService, $scope) {
super($q);
// other construtor-related activity
this.isInForgottenPasswordMode = false;
this.passwordSent = false;
}
// ..behaviours and views can interact with isInForgottenPasswordMode
// and passwordSent as if they were on a $scope..
}
}
When viewing the scope on the view with an AngularJS Batarang, I can see that the LoginController has a scope that contains these two properties - inForgottenPasswordMode and passwordSent.
Can someone please explain how this is happening? Is it not necessary to bind onto the scope? Is this something I have missed regarding AngularJS?
Upvotes: 1
Views: 53
Reputation: 11388
In angular 1.4 and further, you can access $scope
values with this
.
It's used to enable the Controller as
syntax.
You can have a look at this :
http://toddmotto.com/digging-into-angulars-controller-as-syntax/
Upvotes: 1