角度分量内的角度分量? `<comp0><comp1></comp1></comp0>`
Posted
技术标签:
【中文标题】角度分量内的角度分量? `<comp0><comp1></comp1></comp0>`【英文标题】:Angular component inside angular component? `<comp0><comp1></comp1></comp0>` 【发布时间】:2020-05-31 22:05:00 【问题描述】:我尝试过使用ng-template
和ng-container
,但我不知道如何在组件中包含组件……
import Component from '@angular/core';
@Component(
selector: 'hello',
// template: `<h1>Hello</h1><div>I am in a div<ng-container></ng-container>; now this is end</div>`,
template: `<h1>Hello</h1><div>I am in a div<ng-template></ng-template>; now this is end</div>`,
styles: [`h1 font-family: Lato; `]
)
export class HelloComponent
@Component(
selector: 'intestines',
template: 'Eww',
styles: []
)
export class IntestinesComponent
@Component(
selector: 'my-app',
template: `<hello><intestines></intestines></hello>`,
styles: [ 'p font-family: Lato; ' ]
)
export class AppComponent
https://stackblitz.com/edit/angular-2b2yl3
【问题讨论】:
做:template: `<h1>Hello</h1><div>I am in a div<ng-content></ng-content>; now this is end</div>`.
【参考方案1】:
使用ng-content
@Component(
selector: 'hello',
template: `<h1>Hello</h1><div>I am in a div<ng-content></ng-content>; now this is end</div>`,
styles: [`h1 font-family: Lato; `]
)
export class HelloComponent
同时检查this article 可能对你有用。
【讨论】:
以上是关于角度分量内的角度分量? `<comp0><comp1></comp1></comp0>`的主要内容,如果未能解决你的问题,请参考以下文章