How to pass directive parameter to its controller?
I use directive:
<directive value="ctrl.item"></directive>
.directive('directive', [ function () {
return {
restrict: 'AE',
scope: {
value: '=value'
},
templateUrl: 'item.html',
controller: 'Item as item'
};
}])
I want to read value
inside a directive's controller:
.controller('Item', [function Item () {
console.log(this.value);
}])
Is it possible to do using this
?
It should be on your directive's
scope
, and you can access it inside thelink
method like so:Set the bindToController property to
true
Use the
$onInit
life-cycle hook