【发布时间】:2018-05-30 19:10:16
【问题描述】:
我有两个组件。一个是卡片仪表板(使用 ng generate @angular/material:material-dashboard --name=my-dashboard 创建),其中卡片的创建方式如下:
<div class="grid-container">
<h1 class="mat-h1">Dashboard</h1>
<mat-grid-list cols="2" rowHeight="350px">
<mat-grid-tile *ngFor="let card of cards" [colspan]="card.cols" [rowspan]="card.rows">
<mat-card class="dashboard-card">
<mat-card-header>
<mat-card-title> {{card.title}}
<button mat-icon-button class="more-button" [matMenuTriggerFor]="menu" aria-label="Toggle menu">
<mat-icon>more_vert</mat-icon>
</button>
<mat-menu #menu="matMenu" xPosition="before">
<button mat-menu-item>Expand</button>
<button mat-menu-item>Remove</button>
</mat-menu>
</mat-card-title>
</mat-card-header>
<mat-card-content class="dashboard-card-content">
<div>{{ card.content }}</div>
</mat-card-content>
</mat-card>
</mat-grid-tile>
</mat-grid-list>
</div>
而且是这样填充的:
export class DashComponent {
cards = [
{ title: 'Character', cols: 2, rows: 1, content: '<app-character-sheet></app-character-sheet>' },
{ title: 'Card 2', cols: 1, rows: 1 },
{ title: 'Card 3', cols: 1, rows: 2 },
{ title: 'Card 4', cols: 1, rows: 1 }
];
}
我想用不同的组件填充卡片。但是当我像你在上面看到的那样尝试它时(使用 content 变量),HTML 没有解析选择器。卡片只是文字内容:.
如何用组件动态填充我的卡片?
干杯
【问题讨论】:
-
{{x}}是字符串插值,因此它最终会作为字符串传递给 html div。您可以通过将属性绑定到 div 来做到这一点。
标签: html angular typescript