When you use the ControllerAs syntax, a property is created on the $scope object, which is an alias of your controller. for example, ng-controller="MainCtrl as vm" gives you $scope.vm . $scope implied in HTML, so accessing vm.name in HTML is the same as accessing $scope.vm.name in JavaScript.
In the controller, you can access this.name or $scope.vm.name , they will be functionally equivalent. However, in other controllers, this will refer to this particular controller, and thus this.name will not work.
Therefore, in this case, you can access the required property in the directive controller using $scope.vm.name . http://plnkr.co/edit/WTJy7LlB7VRJzwTGdFYs?p=preview
However, you probably also want to use the ControllerAs syntax with this directive; in this case, I recommend using a unique name instead of using vm for your controller names, which can help determine which controller you are accessing. MainCtrl as main , and then referring to main.name will be much clearer.
I recommend using a scope if possible, however, as this will completely eliminate the need to embed $scope in your directives and allow your directive to be self-contained and reused.
A side note, bindToController: true, does nothing unless you use the selection area; when you use the isolation area, it creates the properties of the isolated controller to match the passed area, allowing you to access the passed values โโwithout the need for $scope .
source share