I'm trying to use classes to define a directive. The html does show up and it does show it's calling the ctor and the controller functions. However, I have a class method that I want to call in the html from a ng-click but it's not getting called.
Note I'm working in 1.3x an can't upgrade at this time.
https://plnkr.co/edit/cWyyCahfoWWwk0UN49ep?p=preview
Directive:
class StoreHours{
constructor(){
console.log("inside ctor");
this.restrict = 'E';
this.templateUrl = 'storeHours.html';
this.bindToController = true;
this.controllerAs = 'vm';
this.scope = {
hours: '=',
index: '=',
addNewHour: '&'
};
}
controller(){
console.log("inside controller");
}
// the member metod that I want ng-click to call
addNew(newHour){
var vm = this;
console.log("addNew()");
vm.addNewHour({ hour: newHour, index: vm.index });
vm.newHour = "";
}
// don't need this but just showing
link(scope, element, attrs){
}
}
app.directive('storeHours', () => new StoreHours);
HTML:
<div style="background-color: gray;">
<h1>I'm the store hours component!</h1>
<li ng-repeat="hrs in vm.hours">
{{hrs}}
</li>
<input type="text" ng-model="vm.newHour" />
<button ng-click="vm.addNew(vm.newHour)">Add New</button>
</div>