angulartypecript组件不显示模板

时间:2016-07-15 14:56:38

标签: angularjs typescript

遵循这个问题和解决方案: AngularJS directive not displaying the template

我想尝试使用角度组件和打字稿,但我似乎无法使其正常工作。该组件没有显示。

我的HTML看起来像这样:

<div ng-app="SuperHero">
    <super-man></super-man>
</div>

我的打字稿看起来像这样:

module Application.Components {
    export class superMan implements ng.IComponentOptions {
        template: string = "<h1>Hello from component</h1>";
    }
}

var appModule = angular.module("SuperHero", []);
appModule.component("superMan", () => Application.Components.superMan);

这里有一个小提琴:http://jsfiddle.net/589301uo/2/

1 个答案:

答案 0 :(得分:0)

组件定义采用配置对象,而不是函数。因此,在您的示例中,您应该使用new Application.Components.superMan()而不是() => Application.Components.superMan

还要注意组件是以角度1.5添加的,而你的小提琴使用的是旧版本。

Here's工作演示。

相关问题