We can use $scope
as a namespace in angularJS
angular.module('myApp',[])
.controller("myController", function($scope){
$scope.info = "Hello";
})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="myApp">
<div ng-controller="myController">
<input type="text" ng-model="info">
{{info}}
</div>
</body>
or we can use this
explicitly in controller
and use the controller name as namespace in view like:
angular.module('myApp',[])
.controller("myController", function(){
this.info = "Hello";
})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="myApp">
<div ng-controller="myController as ctrl">
<input type="text" ng-model="ctrl.info">
{{ctrl.info}}
</div>
</body>
My question is what's the difference and what choose to use?