Clear input - ng-model - change

0

I have md-select where according to the selected, I create some div's using ng-if . These created divs have in 02 of them, equal models (ng-model). Therefore, when performing the md-select switch to another that has the same model, the value set in this field will be maintained. I would like to check the possibility of clearing such a template whenever there was a field change!?

<div ng-if="input.Tipo == 4">                                        
    <div class="col-md-8">                                      
        <md-input-container>
            <label ng-if="input.Descricao">{{ input.Descricao }}</label>
            <label ng-if="input.Descricao == undefined"> Data </label>
            <md-select ng-model="input.SequenciaTipoData">
                <md-option value="1">Dia Atual</md-option>
                <md-option value="2">Ontem</md-option>
                <md-option value="3">Início do Mês Atual</md-option>
                <md-option value="4">Início do Mês Anterior</md-option>
                <md-option value="5">Fim do Mês Anterior</md-option>
                <md-option value="6">Data Fixa</md-option>
                <md-option value="7">Retroagir X Dias</md-option>                                                    
            </md-select>                                            
        </md-input-container><br />           
    </div>

    <div ng-if="input.SequenciaTipoData == 1 || input.SequenciaTipoData == 2">
        <div class="col-md-2">
            <md-input-container>
                <label>Horário</label>
                    <input type="text" ng-model="input.Valor" ng-pattern="/^(0[0-9]|1[0-9]|2[0-3])(:[0-5][0-9]){2}$/" required>
            </md-input-container>
        </div>                          
    </div>                                   

    <div ng-if="input.SequenciaTipoData == 6">
        <div class="col-md-2" >
            <md-datepicker ng-model="input.Valor"  md-placeholder="informe data" md-current-view="month" md-open-on-focus required></md-datepicker>
        </div>
    </div>
    <div ng-if="input.SequenciaTipoData == 7">
        <div class="col-md-2" >
            <md-input-container class="md-block" flex-gt-sm>
                <label>Quantidade Dias</label>
                <input ng-model="input.Valor" maxlength="365" ng-pattern="/^[0-9]*$/" required>
            </md-input-container>
        </div>
    </div>
</div>
    
asked by anonymous 27.06.2018 / 13:54

1 answer

1

AngularJS has a policy for detecting changes: ng-change

My suggestion is that you create a function to clean what you want to clean and use ng-change in select.

Eg: <md-select ng-model="input.SequenciaTipoData" ng-change="limparModel()">

Good luck! :)

    
13.07.2018 / 17:23