Using AngularJS 1.5 and TypeScript I am writing a directive and want to define an attribute in my view that gets passed into the directive and then used to output to a template. I have tried to follow some examples such as this one, but my directive template isn't binding to the attribute.
HTML from page:
<my-directive name="John"></my-directive>
Directive:
module myApp.directives {
"use strict";
export class myDirective {
static directiveId = 'myDirective';
scope = {};
bindToController = {
name: '='
};
restrict = 'EA';
controller = controllers.NameController.ControllerId;
controllerAs = 'vm';
template = '<h1>Name: {{ vm.name }}</h1>';
static $inject = [];
constructor() { }
static instance() {
return new myDirective();
}
}
angular.module("myApp").directive(myDirective.directiveId, myDirective.instance);
}
Controller (not really sure I need anything in the constructor?):
module myApp.controllers {
"use strict";
export class NameController {
static ControllerId = "NameController";
name: string;
constructor(name: string){
this.name = name;
}
}
angular.module("myApp").controller(NameController.ControllerId, NameController);
}