gpt4 book ai didi

javascript - Material 扩展面板内容 - ng-template?

转载 作者:行者123 更新时间:2023-11-28 04:45:17 26 4
gpt4 key购买 nike

我有以下代码,是我从这里偷来的: https://github.com/angular/material2/blob/master/src/demo-app/expansion/expansion-demo.html

  <mat-expansion-panel class="mat-expansion-demo-width" #myPanel>

<mat-expansion-panel-header [expandedHeight]="expandedHeight" [collapsedHeight]="collapsedHeight">
<mat-panel-description>Click here to change view format.</mat-panel-description>
<mat-panel-title>View Controls</mat-panel-title>
</mat-expansion-panel-header>

<ng-template matExpansionPanelContent>
This is the content text that makes sense here.
<mat-checkbox>Trigger a ripple</mat-checkbox>
</ng-template>

foo bar baz

<mat-action-row>
<button mat-button (click)="myPanel.expanded = false">CANCEL</button>
</mat-action-row>
</mat-expansion-panel>

一个问题-我很困惑,因为<ng-template>里面的内容标签不显示,但显示“foo bar baz”。那么<ng-template>里面的内容是做什么用的呢?为什么不显示?

最佳答案

<ng-template>在您调用它之前不会呈现。试试这个:

<mat-expansion-panel class="mat-expansion-demo-width" #myPanel>

<mat-expansion-panel-header [expandedHeight]="expandedHeight" [collapsedHeight]="collapsedHeight">
<mat-panel-description>Click here to change view format.</mat-panel-description>
<mat-panel-title>View Controls</mat-panel-title>
</mat-expansion-panel-header>

<ng-container *ngTemplateOutlet="matExpansionPanelContent"></ng-container>

foo bar baz

<mat-action-row>
<button mat-button (click)="myPanel.expanded = false">CANCEL</button>
</mat-action-row>
</mat-expansion-panel>

<ng-template #matExpansionPanelContent> <-- Note the #hashtag
This is the content text that makes sense here.
<mat-checkbox>Trigger a ripple</mat-checkbox>
</ng-template>

这样你就可以构建<ng-template>一次,然后在所有地方重复使用它。

关于javascript - Material 扩展面板内容 - ng-template?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48550879/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com