When do we use $scope, versus not use it? It seems I can get away without it, at least as far as the controller definition is concerned (See following examples).
Am I correct in this? Can you please provide an example where this/self would not work, and we are forced to use $scope?
// Method 1: Not using $scope
function LoginController() {
var self = this;
this.username = "";
this.password = "";
this.login = function() {
if( (self.username === 'admin') && (self.password === 'admin') ) {
// Do something
}
}
}
// Method 2: Using $scope
function LoginController($scope) {
$scope.username = "";
$scope.password = "";
$scope.login = function() {
if( ($scope.username === 'admin') && ($scope.password === 'admin') ) {
// Do something
}
}
}