I wanted to fill a field of professions with a list of professions already registered for the end user, as a way to help the user follow a pattern for the names. Then I thought one to use a datalist that showed the already registered professions. I created a json that lists the professions already registered in the table, as well as a controller using angularjs that pulls that data. Searching, I found two ways to do my datalist, one using the option tag, another using the select tag, the problem is that none works the way I wanted.
When I use the option, it renders as follows:
WhenIuseselect,itrenderslikethis:
Belowaremycodes:
Controller:
angular.module('myApp').controller('profissoesCtrl',function($scope,$http){$scope.profissoes=[];varcarregarProfissoes=function(){$http.get("ListaProfissoes.php").then(function(response){
$scope.profissoes=response.data;
});
};
carregarProfissoes();
My html, using the option:
<datalist ng-controller="profissoesCtrl" id="profissoes">
<option ng-repeat="p in profissoes" value="{{p}}">
</datalist>
My html using select:
<datalist ng-controller="profissoesCtrl" id="profissoes">
<select class="oculto" ng-model="aluno.profissao" ng-options="p.profissao as p.profissao for p in profissoes" > </select>
</datalist>
Thanks in advance!