I recently read John Pap, a self-confident AngularJS configuration guide, and noticed his agreement on controllers:
function Customer () { var vm = this; vm.name = {}; vm.sendMessage = function () { }; }
When this is used in the controller, it works fine, as you can do something like this (example):
<div ng-controller="Customer as customer"> {{ customer.name }} </div>
However, I'm more curious how this works with directives that rely on this controller. For example, using $scope on my controller, I can do something like this:
testModule.directive("example", function(){ return{ template: "Hello {{customer}}", controller: "exampleCtrl" } }); testModule.controller("exampleCtrl", exampleCtrl); function exampleCtrl($scope){ $scope.message = "Display this"; }
But I can not do this using this.message :
testModule.directive("example", function(){ return{ template: "Hello {{customer}}",
So my question is: how does this work in the directive? I tried using:
{{customer}} {{this.customer}} {{exampleCtrl.customer}}
And nobody is working. As you can see, I shoot in the dark and do not understand the differences and how I can use this in Angular instead of scope . Also, since this is not a convention, I have not been able to find many resources talking to it, since it understands JS more than Angular.
Any help is appreciated!