Я работаю над угловой директивой POC. Здесь у меня есть HTML-страница и класс контроллера. У меня есть метод в моем классе typescript, который возвращает директиву. Также у меня есть заполнитель для этой директивы на странице HTML. Как я могу связать эти два.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>TypeScript HTML App</title>
<link rel="stylesheet" href="app.css" type="text/css" />
<script src="scripts/angular.js"></script>
<script data-main="main" src="scripts/require.js" type="text/javascript"></script>
</head>
<body ng-controller="TypeScriptController as TSCtrl">
<helloworld> </helloworld>
</body>
</html>
/////класс контроллера
export class TypeScriptController {
name: string;
place: string;
output: string;
text: string;
helloworld: ng.IDirective;
protected ngModule: ng.IModule = null;
constructor() {
this.name = "Obama";
this.place = "America";
this.text = "welcome";
this.helloworld = this.getCustomDirective();
//how can link this helloworld directive to the html
}
getCustomDirective(): ng.IDirective {
return {
restrict: 'E',
replace: true,
controller: [TypeScriptController],
controllerAs: "TSCtrl",
//templateUrl: "first.html"
template: '<h1>{{TSCtrl.place}}</h1>'
};
}
}
angular.element(document).ready(() => {
var main: TypeScriptController = new TypeScriptController();
});
Как связать директиву helloworld с файлом html. У меня нет имени «ng-app», чтобы сделать что-то вроде ..
angular.module('myApp').directive('myDirective', myDirective);
Я хочу зарегистрировать директиву внутри класса, а не за его пределами. Я хочу создать модуль или что-то подобное внутри класса, а затем использовать его для регистрации директивы.