app.js
angular.module("FipeApp", []);
angular.module("FipeApp").controller("FipeAppCtrl", function($scope, $http) {
$scope.app = "FIPE APP";
$scope.tipos = [{
nome: "Carros",
id: "carros"
}, {
nome: "Motos",
id: "motos"
}, {
nome: "Caminhões",
id: "caminhoes"
}, ];
//$scope.tipo = [];
$scope.tipoSelec = '';
//$scope.marca = [];
//$scope.marcaSelec = '';
var carregarMarcas = function() {
$http.get('https://crossorigin.me/http://fipeapi.appspot.com/api/1/' + $scope.tipoSelec + '/marcas.json').success(function(data) {
$scope.marcas = data;
}).error(function(data, status) {
$scope.message = "Aconteceu um problema: " + data;
});
};
carregarMarcas();
});
index.html
<html lang="pt-BR" ng-app="FipeApp">
<body ng-controller="FipeAppCtrl">
<div class="container">
<div class="linha">
<div class="coluna-5">
<h4 class="header">{{app}}</h4>
<select ng-model="tipoSelec" ng-change="carregarMarcas()" ng-options="tipo.nome for tipo in tipos">
<option value="">Seleciona um Tipo de Veiculo</option>
</select>
<select ng-model="marcaSelec" ng-disabled="!tipoSelec" ng-options="marca.fipe_name for marca in marcas">
<option value="">Seleciona uma Marca</option>
</select>
{{tipoSelec.id}} {{marcaSelec.id}}
</div>
</div>
</div>
</body>
I need to get the typeSelec.id selected by the client and concatenate it in the URL that will get the JSON with the name of the Marks, tried in several ways already and nda, I am noob yet =)