I am new to Angular JS and have been taught it the 'this' way:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script>
var app = angular.module('Comment',[]);
app.controller('CommentCtrl',function(){
this.welcome = 'Hello!';
});
</script>
<p ng-app='Comment' ng-controller='CommentCtrl as ctrl'>
Angular says: {{ ctrl.welcome }}
</p>
Which shows 'Angular says: Hello!' inside the paragraph.
However, every angular application I have ever seen has used '$scope' instead of 'this', like I was taught.
Could someone please explain a few of the pros and cons of each, and what exactly $scope is in terms that I can understand?
Thanks.