[英]How to apply style through @input property, I want to increase width of mat-autocomplete in angular
One of friend rightly pointed out to use property @input as shown in enter link description here .一位朋友正确地指出要使用属性@input,如在此处输入链接描述中所示。 I want to apply new style and change the width of
mat-autocomplete
.So drop down width is still big.我想应用新样式并更改
mat-autocomplete
的宽度。所以下拉宽度仍然很大。
I am new Angular, I don't know how to use this property, but here is what I tried this is not working.我是新的 Angular,我不知道如何使用这个属性,但这是我尝试过的,这是行不通的。
compoenent.ts组件.ts
@Input() panelWidth: string | number;// I tried initializing this here for ex:50px, gives error
tried applying property as attribute to mat-autocomplete as shown below尝试将属性作为属性应用到 mat-autocomplete,如下所示
<mat-autocomplete panelWidth ="170px" #auto="matAutocomplete" [displayWith] = "displayFn">
Here is the whole template.html code snippet which does autocomplete这是整个模板。html 代码片段自动完成
<mat-form-field >
<input matInput [matAutocomplete]="auto" [formControl]="customerFilterControl">
<mat-autocomplete panelWidth ="170px" #auto="matAutocomplete" [displayWith] = "displayFn">
<mat-option *ngFor="let option of (filteredOptions | async)" [value] ="option">
{{option.name}} {{option.type}}
</mat-option>
</mat-autocomplete>
</mat-form-field>
Don't use @Input() panelWidth
in component.ts, this is the definition in documentation.不要在 component.ts 中使用
@Input() panelWidth
,这是文档中的定义。 As end user, you should use as as follows,作为最终用户,您应该按如下方式使用,
<mat-autocomplete panelWidth ="170px" ...
// define variable in class
widthOfPanel = '170px';
use it in HTML with binding,在 HTML 中使用它并绑定,
<mat-autocomplete [panelWidth]="widthOfPanel" ...
Try this in your styles在您的 styles 中试试这个
/deep/ .mat-autocomplete-panel {
min-width: 133px;
max-width: 340px;//your desire width
width: 100%;
}
Use /deep/
when you style in inner component css
else don't use it if you style in globally in stlye.scss
在内部
component css
中设置样式时使用/deep/
否则,如果您在stlye.scss
中全局设置样式,请不要使用它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.