Select md-option with ng-click

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 the vacancy of interest above, automatically in the form this option must be marked in the select. Has anyone ever had to do something similar? I have no idea how I can do this.

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

Follow the 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);
    }
    
asked by anonymous 08.06.2017 / 19:22

1 answer

2

It's actually quite simple to solve this. In the button you made the call of the function ng-click="vm.rolar_formulario (v.name)" , passing as a parameter so I understood the name of the position.

In your select the variable model ng-model="vm.form.cargo" so I understand it is also storing the name of the job, as this is what is set in the value property="{{c.name}}" .

Knowing this you only need to do something like this in the function:

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

Just one more tip, in the md-option tag try using ng-value rather than value, just for the sake of convention.

    
08.06.2017 / 19:55