0
When activating the addAgent method the item is added but the selected option continues and the default option should be selected again.
Controller
$scope.addAgent = function (selectedAgent) {
if (null == selectedAgent) {
alert('Selecione um Agente para adicionar.');
return;
}
$scope.agents.push(selectedAgent);
//mesmo resetando aqui, o último option selecionado continua marcado
$scope.selectedAgent = '';
};
View
<label>Agentes</label>
<select class="form-control"
ng-model="selectedAgent"
ng-options="option as option.name
group by option.type for option in availableAgents track by option.id">
<option value="" ng-selected="selectedAgent ==''">Selecione</option>
</select>
<a ng-click="addAgent(selectedAgent)"
class="btn btn-sm btn-success" title="Adicionar Agente"><i class="fa-plus fa"></i></a>
Example ngOption data format
var availableAgents = [
{id:1, name:"aaaa", "type":"A"},
{id:2, name:"aaaa2", "type":"A"},
{id:3, name:"bbbb", "type":"B"},
];
your plunker is not complete.
– celsomtrindade
@Celsomtrindade tests now. Thank you for warning.
– adelmo00
Just to get a better view of https://plnkr.co/edit/eO3qJk0T4MZGFzBSddeL?p=preview but really, if the solution was just to add $Scope.Agents, perfect =D
– celsomtrindade