Search code examples
angularjsionic-frameworkionic-view

How to Listing only items according to a past variable, Like a global variable


Good Morning Ionics!

I want to show a list only with products from a single selected vendor.

In my StateProvider I send the selected data, which should be the filter:

.state("nhaac.ofertas_restaurante", {
        url: "/ofertas_restaurante/:cadastra_oferta_cod_fornecedor",

And in the view that I want to present data only of the "cadastra_oferta_cod_fornecedor" selected I put:

<div class="card" ng-repeat="item in ofertass track by $index" ng-if="cadastra_oferta_cod_fornecedor === item.cadastra_oferta_cod_fornecedor" href="#/nhaac/ofertas_singles/{{item.cadastra_oferta_cod_oferta}}" >  

But it does not list anything. It goes blank. Can someone help me?

Thank you.


Solution

  • You have to inject $stateParams in the controller and grab the params you want like so:

    myApp.controller("MyCtrl", ["$scope", "$stateParams", function($scope,$stateParams){
          $scope.cadastra_oferta_cod_fornecedor = $stateParams.cadastra_oferta_cod_fornecedor;   
        }
    ]);
    

    Hope it helps =)