What you need to do is use the same ngModel
, so much on the input as in the select, thus:
<select name="funcionario" id="funcionario" class="form-control" ng-model="funcionarioSelecionado" required>
<option ng-repeat="funcionario in funcionarios" value="{{ funcionario.cargo }}">{{ funcionario.nome }}</option>
</select>
<input type="text" class="form-control" ng-model="funcionarioSelecionado" />
Also note that I changed the value of your option, to apply the correct value to ngModel
, otherwise, it would assign the entire object as value. Thus, when you select an employee, it will display the position in the text field.
By further simplifying your code, you can remove ngRepeat and use only ngOptions, which is the right one to use in a select. So your code would look like this (I removed the html attributes for easy reading):
<select ng-options="funcionario.cargo as funcionario.nome for funcionario in funcionarios" ng-model="funcionarioSelecionado"></select>
<input type="text" ng-model="funcionarioSelecionado" />
Explaining the use of ngOptions
, would be the following:
ng-options="'valor' as 'texto exibido no campo' for 'objeto' in 'array'"