相关疑难解决方法(0)

具有<ng-content>的Angular2根组件

我已经看到了<ng-content>在其他嵌套组件中使用的工作示例(例如http://plnkr.co/edit/Hn393B9fJN6zgfaz54tn),但我还没有设法在根Angular2组件中运行它:

HTML模板:

<html>
    <body>
        <app>
            <h1>Hello, World!</h1>
        </app>
    </body> 
</html>
Run Code Online (Sandbox Code Playgroud)

打字稿中的Angular2组件:

import {Component, View, bootstrap} from 'angular2/angular2';

@Component({
    selector: 'app'
})
@View({
    template: 'Header: <ng-content></ng-content>',
})
export class App {
}

bootstrap(App);
Run Code Online (Sandbox Code Playgroud)

我希望这会产生:

<app>
    Header: <h1>Hello, World!</h1>
</app>
Run Code Online (Sandbox Code Playgroud)

但它没有,内容<app>被忽略了.请参阅Plunker http://plnkr.co/edit/dJlA4SQpy8pnrdyDiy9u上的演示.

我想也许这会再次出现一些Angular2哲学或其他东西,所以它甚至不支持,但我的用例与我认为的第一个工作演示非常相似.

angular

20
推荐指数
2
解决办法
2万
查看次数

标签 统计

angular ×1