Change label class to active after angular http request

0

I have a component of the bootstrap design material that after an http request it is populated, the problem is that it does not change to the "active" class, taking the result of the photo.

<divclass="md-form form-lg">
            <input type="text" id="form2" value="{{cliente.whatsapp}}" class="form-control">
            <label for="form2">Whatsapp</label>
          </div>

If I try to change the label class="active", I still can not get the label result at the top, how can I fix this?

<label class="active" for="form2">Whatsapp</label> does not work

I should apply the active class when it has value in the input.

    
asked by anonymous 10.07.2018 / 15:59

2 answers

0

You have an option to do this "check" with only CSS used to pseudo-class :placeholder-shown . So you will not even need to insert a class .active into the label, since the check is in input + label by css

It works like this:

If input has a placeholder active, that is, if input is empty only with placeholder , usually the label that follows will have red text for example.

However, if something is written inside input , that is, if placeholder is NOT active (because it will have something written inside), the color of label is green.

See the example below to understand better:

input:placeholder-shown + label {
    color: red;
}
input:not(:placeholder-shown) + label {
    color: green;
    font-weight: bold;
}
Escreva algo nesse input<br>
<input type="text" placeholder="com placeholder / sem value" value="" name="" id="app">
<label for="app">Vai trocar de cor quando preencher input</label>

<br>
<br>
<br>

Esse input já tem um valor no value<br>
Apague  o texto do input!<br>
<input type="text" placeholder="meu placeholder" value="sem placeholde / com value" name="" id="app">
<label for="app">Já está sem o placeholder então é verde</label>

OBS 1: This is not a native implementation of Bootstrap Material, but as you saw it can be easily deployed.

OBS 2: No works in IE and Edge link

    
10.07.2018 / 16:16
0

You could use ngClass

It has the following syntax ngClass="{classe: condicao}"

<div class="md-form form-lg">
            <input [ngClass]="{active: cliente.whatsapp}" type="text" id="form2" value="{{cliente.whatsapp}}" class="form-control">
            <label for="form2">Whatsapp</label>
</div>
    
10.07.2018 / 16:36