In my project I have a dropdown, iterated from an array. Note that in the array I have a key called default that is set to true or false. I would like the dropdown defalt value to come with the key set to true.
If I do this: $scope.nfe.naturezaOperacao = $scope.cfops[0];
, it works, however, I'm setting it static, I'd like you to set the default according to the default key.
JS:
angular.module('nfe', []).controller('nfeController', function ($scope, $http) {
$scope.nfe = [];
$scope.cfops = [
{codigo: "5.102", descricao : "Venda a vista 12%", elo: "012", default: false},
{codigo: "5.102", descricao : "Venda a vista 17%", elo: "017", default: true}
];
//$scope.nfe.naturezaOperacao = $scope.cfops[0];
});
HTML:
<select
class="form-control"
name="NF_NATUREZA_OPERACAO"
id="NF_NATUREZA_OPERACAO"
data-ng-model="nfe.naturezaOperacao"
data-ng-init=""
data-ng-options="cfop.descricao for cfop in cfops">
</select>