在Angular 8中,当在多个ng-content中查找嵌套组件时可能会遇到一些问题。以下是一个可能的解决方案,包含使用代码示例:
:host ::ng-deep .content1 {
/* 样式规则 */
}
:host ::ng-deep .content2 {
/* 样式规则 */
}
import { Component, QueryList, ViewChildren, AfterViewInit } from '@angular/core';
import { ChildComponent } from './child.component';
@Component({
selector: 'parent-component',
template: `
`
})
export class ParentComponent implements AfterViewInit {
@ViewChildren(ChildComponent) childComponents: QueryList;
ngAfterViewInit() {
this.childComponents.forEach(childComponent => {
// 处理子组件
});
}
}
请注意,这只是一个可能的解决方案,并不一定适用于所有情况。具体解决方法取决于您的实际需求和项目的结构。