[英]Remove outer component tag from html in angular 7
Similar questions have been asked and usually people suggest a change in the component selector.有人问过类似的问题,通常人们建议更改组件选择器。
In my case, is doesn't work.在我的情况下,是行不通的。
Here's the scenario:这是场景:
I am using Angular Material 's Expansion panel an I want to have a component for each individual item in the panel:我正在使用Angular Material的Expansion 面板,我希望面板中的每个单独项目都有一个组件:
@Component({
selector: '[app-panel-item]',
templateUrl: './panel-item.component.html',
styleUrls: ['./panel-item.component.scss']
})
export class PanelItemComponent
<mat-expansion-panel>
<mat-expansion-panel-header>
<mat-panel-title>
Title
</mat-panel-title>
<mat-panel-description>
desc
</mat-panel-description>
</mat-expansion-panel-header>
BODY
<mat-action-row>
<button mat-raised-button>Button</button>
</mat-action-row>
</mat-expansion-panel>
The issue is that, using either <app-panel-item>
or <div app-panel-item>
creates an outer html tag that messes up the styling.问题是,使用
<app-panel-item>
或<div app-panel-item>
会创建一个外部 html 标记,该标记会弄乱样式。 I tried removing <mat-expansion-panel>
from the directive and using <mat-expansion-panel app-panel-item>
but you can't have 2 structural selectors together.我尝试从指令中删除
<mat-expansion-panel>
并使用<mat-expansion-panel app-panel-item>
但你不能同时拥有 2 个结构选择器。
Expected layout:预期布局:
Actual result:实际结果:
How can I actually remove that outer tag created by the component?我怎样才能真正删除由组件创建的外部标签?
EDIT: Stackblitz编辑: Stackblitz
If the problem only is border-radius you can add this style into your styles.css如果问题只是边界半径,您可以将此样式添加到您的styles.css
.mat-accordion app-panel-item .mat-expansion-panel:not(.mat-expanded), .mat-accordion app-panel-item .mat-expansion-panel:not(.mat-expansion-panel-spacing) {
border-radius: 0;
}
.mat-accordion app-panel-item:first-of-type .mat-expansion-panel {
border-top-right-radius: 4px;
border-top-left-radius: 4px;
}
.mat-accordion app-panel-item:last-of-type .mat-expansion-panel {
border-bottom-right-radius: 4px;
border-bottom-left-radius: 4px;
}
here is the example with styles in styles.css这是styles.css中的样式示例
https://stackblitz.com/edit/angular-3xmec5 https://stackblitz.com/edit/angular-3xmec5
component.css组件.css
::ng-deep .mat-accordion app-panel-item .mat-expansion-panel:not(.mat-expanded),::ng-deep .mat-accordion app-panel-item .mat-expansion-panel:not(.mat-expansion-panel-spacing) {
border-radius: 0;
}
::ng-deep .mat-accordion app-panel-item:first-of-type .mat-expansion-panel {
border-top-right-radius: 4px;
border-top-left-radius: 4px;
}
::ng-deep .mat-accordion app-panel-item:last-of-type .mat-expansion-panel {
border-bottom-right-radius: 4px;
border-bottom-left-radius: 4px;
}
stackblitz example with ::ng-deep使用 ::ng-deep 的 stackblitz 示例
https://stackblitz.com/edit/angular-39tbxt https://stackblitz.com/edit/angular-39tbxt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.