如何使用Angular在页面加载上设置表单元素/值的不透明度?

时间:2017-11-09 19:58:47

标签: angular

我输入的是dynamically setting/creating the placeholder text

一切都很好。例外情况是,如果默认情况下任何输入在页面最初加载时都具有值,则输入的值将设置为不透明度为0.

如何检查输入是否有值,如果是,则输入的不透明度为1?

template.html

<input type="search" matInput placeholder="My Placeholder" 
    aria-label="My Placeholder" 
    [matAutocomplete]="mySearch" 
    [formControl]="myCtrl 
    (focus)="onInputFocus()" 
    [(ngModel)]="myModel">

1 个答案:

答案 0 :(得分:0)

您可以尝试在输入上使用NgStyle

例如:

<强> template.html

<input type="search" matInput placeholder="My Placeholder" 
    aria-label="My Placeholder" 
    [matAutocomplete]="mySearch" 
    [formControl]="myCtrl 
    (focus)="onInputFocus()" 
    [ngStyle]="{'opacity':myAttribute.myVaue !== '' ? '1' : '' }" // Set the default opacity
    [(ngModel)]="myModel">