0
I wanted that when filling the field of professions, a list of the professions already registered for the end user would appear, as a way to help the user follow a pattern for the names. So I thought one would use a datalist that showed the professions already registered. I created a json that lists the professions already registered in the table, as well as a controller using Angularjs that pulls this data. Searching, I found two ways to make 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:
When I use select, it renders like this:
Below are my codes:
Controller:
angular.module('myApp').controller('profissoesCtrl', function ($scope, $http) {
$scope.profissoes = [];
var carregarProfissoes = 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>
From now on, I thank everyone who answers!
try to use
response.data.profissao
with option, like this:$scope.profissoes=response.data.profissao;
– João Victor Souza
I tried to do this but it didn’t work, it returns Undefined when giving a console.log in $Scope.profissoes trying this way.
– Adriano.Eduardo
It was a silly mistake, in the options tag I should have pasted the value with p.professional, then it worked out, anyway, thank you very much
– Adriano.Eduardo