【发布时间】:2016-01-20 10:38:33
【问题描述】:
我正在研究一个角度指令 POC。这里我有一个 HTML 页面和一个控制器类。我的打字稿类中有返回指令的方法。此外,我在 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);
我想从类内部而不是外部注册指令。我想在类内部创建模块或类似的东西,然后用它来注册指令。
【问题讨论】:
标签: angularjs-directive typescript angular-directive