Select Md-option with ng-click

Asked

Viewed 155 times

2

I have a page listing some job openings. Below these vacancies I have a form and in this form there is an option field to select the vacancy of interest. If the user clicks on the position of interest above, automatically in the form this option must be checked in select. Has anyone ever had to do anything like that? 'Cause I have no idea how I can do this.

In the vacancy area I have only one json with the name and description of each vacancy;

Follows code below:

Html:

<li class="col-lg-6 col-md-6 col-sm-12 col-xs-12" ng-repeat="v in vm.vagas">
    <div class="conteudo">
        <div class="titulo">
            <h2>
                {{v.nome}}
            </h2>
        </div>
        <div class="descricao">
            <p ng-bind-html="v.descricao | trustAs">
            </p>
        </div>
        <div class="botao">
            <md-button class="btn_padrao verde hvr-radial-out interesse_btn" ng-click="vm.rolar_formulario(v.nome)">
                Estou interessado
            </md-button>
        </div>
    </div>
</li>

<form class="formulario_trabalhe">
    <md-input-container class="col-lg-6 col-md-6 col-sm-12 col-xs-12 no_left">
        <md-select ng-model="vm.form.cargo" placeholder="Cargo pretendido">
                <md-option ng-repeat="c in vm.vagas" value="{{c.nome}}">{{c.nome}}</md-option>
        </md-select>
    </md-input-container>
</form>

Controller:

vm.vagas = [
            {
                'nome' : 'Auxiliar de serviços gerais',
                'descricao' : '<p>Atuar na área de limpeza, varrer o chão, verificar os materiais de limpeza e demais atividades da função.Desejável experiência na área de limpeza.Ensino Fundamental completo.</p>',
            },
            {
                'nome' : 'Fiscal de limpeza',
                'descricao' : '<p>Aferir cartão ponto, atender funcionários e clientes nos postos de trabalho, remanejamento de funcionários, faltas, férias e demais atividades relacionada ao setor.</p>',
            },
            {
                'nome' : 'Cozinheiro',
                'descricao' : '<p>Atuar no preparo de alimentos, organização do local entre outras atividades.Necessário experiência na área.Ensino Médio completo.</p>',
            }
        ]


 vm.rolar_formulario = function(a){
        $timeout(function() {
            $(".interesse_btn").click(function (){
                $('html , body').animate({
                    scrollTop: $('.determinado').last().offset().top
                });
            });
        });
        console.log(a);
    }

1 answer

2


It’s actually quite simple to resolve this issue. On the button you made the function call ng-click="vm.rolar_formulario(v.name)", passing as parameter what I understood the name of the vacancy.

In your select the model variable ng-model="vm.form.cargo" from what I understand is also storing the name of the vacancy, because that’s what is set in the property value="{{c.name}}".

Knowing this you just need to do something like this in function:

vm.rolar_formulario = function(nomeVaga){
    vm.form.cargo = nomeVaga;
}

Just one more hint, in the Md-option tag try using ng-value instead of value, just for the sake of convention.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.