$scope.init = function() {
$scope.modelo = {};
$scope.marca = {};
$scope.modelo = {};
$scope.modelos = [];
$scope.marcas = [];
$scope.anos = [];
$scope.precocarro=[];
$http.get('https://fipe-parallelum.rhcloud.com/api/v1/carros/marcas').success(function(data) {
$scope.marcas = data;
});
};
$scope.carregarModelo = function() {
$http.get('https://fipe-parallelum.rhcloud.com/api/v1/carros/marcas/' + $scope.marca.codigo + '/modelos').success(function(data) {
$scope.modelos = data.modelos;
})
};
$scope.carregarAno = function() {
$http.get('https://fipe-parallelum.rhcloud.com/api/v1/carros/marcas/' + $scope.marca.codigo + '/modelos/' + $scope.modelo + '/anos').success(function(data) {
$scope.anos = data;
})
};
$scope.consultarPreco = function(){
var url = 'https://fipe-parallelum.rhcloud.com/api/v1/carros/marcas/' + $scope.marca.codigo + '/modelos/' + $scope.modelo + '/anos/' + $scope.anos.codigo;
console.log(url);
$http.get(url)
.success(function (data){
$scope.precocarro = data;
})
.error(function (data, status, headers, config) {
alert('Desculpe, serviço indisponível. Tente novamente mais tarde.')
});
}
$scope.init();
<div class="list" ng-controller="AppCtrl">
<label class="item item-input item-select">
<span class="input-label">Marca</span>
<select id="teste" class="customSel" ng-options="marca as marca.nome for marca in marcas" ng-model="marca" ng-change="carregarModelo()">
</select>
</label>
<label class="item item-input item-select">
<span class="input-label">Modelo</span>
<select id="modelo" class="customSel" ng-model="modelo" ng-change="carregarAno()" >
<option ng-repeat="x in modelos" value="{{ x.codigo }}">{{ x.nome }}</option>
</select>
</label>
<label class="item item-input item-select" ng-model="modelo" ng-change="carregarPreco()" >
<span class="input-label">Ano</span>
<select id="modelo" class="customSel" >
<option value="0" selected>Selecione</option>
<option ng-repeat="x in anos" value="{{ x.codigo }}">{{ x.nome }}</option>
</select>
</label>
<button class="button button-block button-positive" ng-click="consultarPreco(modelo)">Consultar</button>
</div>