Paw*_*ler 4 angular-material angular-material2 angular
我想在选项文本下有其他描述选项的行。默认情况下,mat-select限制字符数,并在行末添加“ ...”。我想有需要的多行选项。stakckblitz演示:https : //stackblitz.com/edit/angular-wj9svw 我的代码:
export class SelectOverviewExample {
foods: Food[] = [
{value: 'steak-0', viewValue: 'Steak longDescription longDescription longDescription longDescription longDescription'},
{value: 'pizza-1', viewValue: 'Pizza longDescription longDescription longDescription longDescription longDescription longDescription v v longDescription'},
{value: 'tacos-2', viewValue: 'Tacos'}
];
}
Run Code Online (Sandbox Code Playgroud)
的HTML:
<mat-form-field>
<mat-select placeholder="Favorite food">
<mat-option *ngFor="let food of foods" [value]="food.value">
{{food.viewValue}}
<b> some additional text text text text texttext </b>
</mat-option>
</mat-select>
</mat-form-field>
Run Code Online (Sandbox Code Playgroud)
.mat-option {
margin: 1rem 0;
overflow: visible;
line-height: initial;
word-wrap: break-word;
white-space: pre-wrap;
}
.mat-option i {
display: block;
font-size: 1.5rem;
opacity: 0.6;
margin-left: 0.5rem;
}
Run Code Online (Sandbox Code Playgroud)
这也很有帮助
使用以下css:
.mat-select-panel mat-option.mat-option {
height: unset;
}
.mat-option-text.mat-option-text {
white-space: normal;
}
Run Code Online (Sandbox Code Playgroud)
要么
/deep/ .mat-select-panel mat-option.mat-option {
height: unset;
}
/deep/ .mat-option-text.mat-option-text {
white-space: normal;
}
Run Code Online (Sandbox Code Playgroud)
示例演示在这里-https://stackblitz.com/edit/angular-material2-issue-ndtstg
我通过编写一个MultiLineOptionDirective扩展<mat-option>并调用与和相同的setLines()函数来解决MatListItemMatGridTile@angular/material/core
<mat-form-field>
<mat-label>Favorite food</mat-label>
<mat-select [formControl]="mySelect">
<mat-select-trigger>{{ mySelect.value }}</mat-select-trigger>
<mat-option *ngFor="let food of foods" [value]="food.value" multiLineOption>
<h4 mat-line>{{ food.value }}</h4>
<p mat-line>{{ food.description }}</p>
</mat-option>
</mat-select>
</mat-form-field>
Run Code Online (Sandbox Code Playgroud)
https://stackblitz.com/edit/angular-material-multi-line-option
编辑:“扩展”可能会被误解,扩展就像指令中扩展元素的功能而不是类扩展基类一样。
| 归档时间: |
|
| 查看次数: |
3321 次 |
| 最近记录: |