I can't figure out why this plnkr isn't working.
I'm trying to bind a simple function from a parent controller to a child custom directive. If I use &
, it doesn't work, but if I use =
or <
, it works fine. I understand this is bad practice, but why does it work and &
doesn't? Maybe I'm missing something very simple?
Here's the script:
JS
var app = angular.module('myApp',['ngMaterial']);
app.controller('mainCtrl',mainCtrl);
function mainCtrl(){
var main = this;
main.test = function(){console.log("test")};
}
app.directive('myDirective',myDirective);
function myDirective(){
return {
scope: {},
controller: myCtrl,
controllerAs: "dir",
bindToController: {
//fn: '&' //This doesn't work
fn: '<' // This works
},
template: '<md-button ng-click="dir.fn()" class="md-raised">click</md-button>'
};
function myCtrl(){
}
}
HTML
<div ng-app="myApp" ng-controller="mainCtrl as main">
<my-directive fn="main.test"></my-directive>
</div>