Angular Search Result in another view

0

I have a search form with 2 selects and 1 submit:

<select ng-model="marca" ng-options="marca.nome_marca for marca in marcas" ng-change="changeMarca()">
<option value="">Selecione uma Marca</option>
</select>

<select ng-model="modelo" ng-options="modelo.nome_modelo for modelo in modelos|filter:{marca_id:marca.marca_id}" ng-change="changeModelo()">
<option value="">Selecione um Modelo</option>
</select>

<button ng-Click="???">BUSCAR</button>

How can I display the result of this search in another view, specifically the route I've already separated for it: #/busca/:marca_id/:modelo_id

I do not know if it was clear, I already have the routes all, I just need to send this to the search controller below:

angular.module("myApp").controller("buscaCtrl", function($scope, $http, $routeParams, estoqueAPI) {
    $scope.loading = true;
    $scope.buscaMarca = $routeParams.marca_id;
    $scope.buscaModelo = $routeParams.modelo_id;

    var carregarEstoque = function () {
        estoqueAPI.getEstoque()
        .success(function (data) {
            $scope.carros = data;
        }).finally(function() { $scope.loading = false; })
    };

    carregarEstoque(); 
});
    
asked by anonymous 20.07.2015 / 18:28

1 answer

1

In front of the excerpt you put in the question the only reason for not working as expected would be to consider the parameters when making the request:

angular.module("myApp").controller("buscaCtrl", function($scope, $http, $routeParams, estoqueAPI) {
    $scope.loading = true;
    $scope.buscaMarca = $routeParams.marca_id;
    $scope.buscaModelo = $routeParams.modelo_id;

    var carregarEstoque = function () {
        estoqueAPI.getEstoque($scope.buscaMarca, $scope.buscaModelo)//<< considerar os parâmetros marca e modelo
        .success(function (data) {
            $scope.carros = data;
        }).finally(function() { $scope.loading = false; })
    };

    carregarEstoque(); 
});

Now ... If you want to know what to put in the "ng-click" of the "SEARCH" button, then it would look something like:

<button ng-Click="buscar()">BUSCAR</button>

And the control:

angular.module("myApp").controller("formCtrl", function($scope, $location) {
    
    $scope.buscar = function(){
        $location.path('/busca/' + $scope.marca.marca_id + '/' + $scope.modelo.modelo_id);
    };    
    
});
    
20.07.2015 / 18:45