1

When browsing angularjs applications and also documentations the use of $scope seems to be frequent and preferred. However, I've also seen examples, like Shaping up with AngularJS where a different method is used to access the information of the controller:

The controller:

angular.module('exampleApp')
.controller('ExampleCtrl', function($scope) { 
   this.info1 = 'Some info'; 
   $scope.scopeinfo = 'More info in $scope';
});

In the view the information can be accessed:

<div ng-controller="ExampleCtrl as ctrl">
<span>{{ctrl.info1}}</span>
<span>{{scopeinfo}}</span>
</div>

Both is working fine. I'm just wondering what is the better 'way'. A lot of modules seem to work better with $scope. However, I kinda like the alternative (is there any name for this?) since I find it easier to distinguish the information, especially when using multiple controllers.

wjentner
  • 525
  • 1
  • 7
  • 16
  • 1
    I think its fair to say its down to personal preference and I also prefer the Controller As syntax as it makes things more readable. This guy discusses this subject at length too http://www.johnpapa.net/angularjss-controller-as-and-the-vm-variable/ – mindparse Feb 08 '15 at 14:16

0 Answers0