我想在我的角度库中简化开发人员的体验。这就是为什么我试图使用带有特定选择的 ng-content,这些选择会自动填充,而无需开发人员添加类。
例子:
应用
app.component.html
<lib-frame-component>
<lib-panel-component [modal]="true"></lib-panel-component>
</lib-frame-component>
图书馆
lib-frame-component.html
<!-- developper should not need to use class="modals-content" to include lib-panel-component(s) -->
<ng-content select='.modals-content'></ng-content>
库框架组件.ts
// get lib-panel-components inserted by the developper
@ContentChildren( LibPanelComponent, { descendants: false } ) directPanels: QueryList<PanelComponent>;
...
// Do something like that somewhere in the life cycle...
this.directPanels.forEach(( panelComponent: LibPanelComponent) => {
if ( panelComponent.modal === true ) {
// TODO : code to insert in ng-content.modals-content
}
}
我怎样才能做到这一点 ?