我使用Angular Material 2,我想要一个卡片头图标按钮。如何将按钮设置在右侧?
我想在标题中设置按钮rop。我该怎么做? 我排除了类别代码,因为没有问题。在打字稿中,代码只是一个for循环来添加更多的牌和一个虚拟方法来点击一张牌。
.healthy-search {
width: 100%
}
.healthy-card {
margin-right: 5px;
margin-bottom: 5px;
}

<div class="flex-container" fxLayout="row" fxLayout.xs="column" fxLayoutAlign="center center" fxLayoutAlign.xs="start">
<div class="flex-item" fxFlex="90%" fxFlex.xs="90%">
<mat-form-field class="healthy-search">
<textarea matInput placeholder="Suche"></textarea>
</mat-form-field>
</div>
</div>
<div class="flex-container" fxLayout="row" fxLayout.xs="column" fxLayoutAlign="center center" fxLayoutAlign.xs="start">
<div class="flex-item" fxFlex="85%" fxFlex.xs="85%">
<mat-expansion-panel>
<!-- Here is the Category -->
<!--Elements of Category -->
<div class="flex-container" fxLayoutWrap fxLayout="row" fxLayout.xs="column" fxLayoutAlign="center center" fxLayoutAlign.xs="start">
<div class="flex-item healthy-card" fxFlex="400px" *ngFor="let number of numbers" (click)="cardClick()">
<mat-card class="example-card">
<mat-card-header>
<mat-card-title>Title {{number}}</mat-card-title>
<button mat-icon-button fxLayoutAlign="right">
<mat-icon aria-label="Example icon-button with a heart icon">Edit</mat-icon>
</button>
<button mat-icon-button fxLayoutAlign="right">
<mat-icon aria-label="Example icon-button with a heart icon">Delete</mat-icon>
</button>
</mat-card-header>
<img mat-card-image src="https://material.angular.io/assets/img/examples/shiba2.jpg" alt="Photo of a Shiba Inu">
<mat-card-content>
<p>
The Shiba Inu is the smallest of the six original and distinct spitz breeds of dog from Japan. A small, agile dog that copes
very well with mountainous terrain, the Shiba Inu was originally bred for hunting.
</p>
</mat-card-content>
</mat-card>
</div>
</div>
</mat-expansion-panel>
</div>
</div>
&#13;
Lyror
答案 0 :(得分:10)
这篇文章相当陈旧,但也许其他人偶然发现了这一点。 (截至编写本答案时,当前版本为Angular Material 6)
我建议使用&lt; mat-card-title-group&gt;属性。来自文档(https://material.angular.io/components/card/overview):
&LT;垫卡标题-组&gt;可用于将标题,副标题和图像合并为一个部分。
这样,标题和描述将捆绑到一个单独的div中,fxFlex容器实际上可以工作。这也允许在左侧添加按钮/图标。
示例可能如下所示:
<mat-card-header>
<mat-icon>help</mat-icon>
<mat-card-title-group>
<mat-card-title>
Title
</mat-card-title>
<mat-card-subtitle>
Subtitle
</mat-card-subtitle>
</mat-card-title-group>
<div fxFlex></div>
<button mat-button>Click me!</button>
</mat-card-header>
答案 1 :(得分:2)
首先从按钮中取走fxLayoutAlign =“right”。 fxLayoutAlign适用于容器。
您需要在标题和按钮之间使用fxFlex的div或其他占位符。这会将按钮推到最后。
<md-card-header fxLayout="row">
<md-card-title >Title </md-card-title>
<div fxFlex></div>
<button md-button>Something</button>
</md-card-header>
答案 2 :(得分:0)
在角形材料7中,这对我来说很不错:
<mat-card>
<mat-card-header>
<mat-card-title-group>
<mat-card-title>
Title
</mat-card-title>
<mat-card-subtitle>
Subtitle
</mat-card-subtitle>
</mat-card-title-group>
<div fxFlex></div>
<div fxLayoutAlign="center center">
<button mat-stroked-button>Click me!</button>
</div>
</mat-card-header>
</mat-card>