英文:
Apply two different classes with panel class depending on the condition in Angular material
问题
I am using mat-select of Angular material. It has panelclass property that can be used to apply class. In parent component I have to style the drop down. The issue is :- I have to apply dynamic class to panelclass but type of panel class is string.
<mat-select panelClass="customClass ? customClass : select-position">
</mat-select>
I want to do something like this but it's not working and in DOM showing complete things inside "" as a string.
I have attached a screenshot of generated HTML.
英文:
I am using mat-select of Angular material. It has panelclass property that can be used to apply class. In parent component I have to style the drop down. The issue is :- I have to apply dynamic class to panelclass but type of panel class is string.
<mat-select panelClass="customClass ? customClass : select-position">
</mat-select>
I want to do something like this but its is not working and in DOM showing complete things inside "" as string
I have attcahed screenshot of generated HTML
答案1
得分: 2
Sure, here's the translated part:
你可以尝试使用方括号和类名用引号括起来的记法,像这样:
<mat-select [panelClass]="customClass ? 'customClass' : 'select-position'"> </mat-select>
英文:
Could you try the notation with the square brackets and the class names in quotes like this:
<mat-select [panelClass]="customClass ? 'customClass' : 'select-position'"> </mat-select>
答案2
得分: 1
Sure, here's the translated content:
- 使用属性绑定(用方括号[]包裹panelClass)
<mat-select [panelClass]="customClass ? 'customClass' : 'select-position'">
</mat-select>
- 使用插值(用{{}}包裹条件)
<mat-select panelClass="{{ customClass ? 'customClass' : 'select-position' }}">
</mat-select>
英文:
You can use it in 2 ways to bind the values:
- Using property binding (Wrapping the panelClass with square brackets [])
<mat-select [panelClass]="customClass ? 'customClass' : 'select-position'">
</mat-select>
- Using interpolation (Wrapping the condition in {{}})
<mat-select panelClass="{{ customClass ? 'customClass' : 'select-position' }}"> </mat-select>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论