When adding a controller to a element directive, for example:
.directive('hello', function() {
return {
restrict: 'E',
replace: true,
transclude: true,
template: '<div class="hello" ng-transclude></div>'
};
});
I'm unable to access the scope of the controller:
.controller('HelloCtrl', function($scope) {
$scope.hello = "Hello World";
});
<hello ng-controller="HelloCtrl">
<h1>Hello Directive</h1>
<p>{{ hello }}</p>
</hello>
In this case {{ hello }} is undefined. The directive doesn't create a child nor an isolated scope. I also tried accessing the property with {{ $parent.hello }}.
What is happening here?
I created a CodePen to demonstrate this behaviour: http://codepen.io/jviotti/pen/ktpbE