I'm trying to set a default value to an md-autocomplete, but it's not possible for me.
I need to be able to perform this function, since I have a service that returns certain parameters that should be automatically completed and, if it does not exist, the user completes the form manually.
I put the current code, but of course, I have no default values, because I have not found or if possible (I understand that), but I do not know if the md-autocomplete functionality itself or not.
Vista
<md-autocomplete
md-selected-item="ciudadItem"
md-search-text="nombreCiudad"
md-items="ciudad in obtenerCiudades(nombreCiudad)"
md-item-text="ciudad.desCiudad"
ng-model="NombreCiudadCups.valor"
placeholder="Nombre ciudad..."
name="Ciudad">
<md-item-template>
<span md-highlight-text="nombreCiudad">{{ciudad.desCiudad}}</span>
</md-item-template>
<md-not-found>
Ciudad no encontrada.
</md-not-found>
</md-autocomplete>
Controller
$scope.obtenerCiudades = function (text) {
text = text.toUpperCase();
var ret = $scope.ciudades.filter(function (d) {
return d.desCiudad.startsWith(text);
});
return ret;
};
$scope.ciudades
is a simple json with a cities, it has no mystery, so I do not attach it.
At this point, all the data is well displayed and searches well, but I need to be able to put a default value, which the user could then erase.