I am trying to put some data in the scope which my directive create. Here is my jsFiddle.
the following code works well
.directive('directive1', function () {
return: {
scope: true,
controller: function ($scope) {
$scope.name = 'world';
}
}
})
<div directive1>
<p>{{ name }}</p>
</div>
but these code do not work
.directive('directive2', function () {
return: {
scope: true,
controller: function () {
this.name = 'world';
},
controllerAs: 'testCtrl'
}
})
<div directive2>
<p>{{ testCtrl.name }}</p>
</div>
Is there anything wrong in my code? or did I misunderstand something about controllerAs?
$scope. What iscontrollerAs?