javascriptangularjsangularjs-ng-repeatng-filter

ngFilter equals with 2 var in angular


I have a little problem, I would like to do a equals with 2 var in ngFilter. I try lot of combinaison, but it doesn't work...

I get the first var here, in $routeParams

function ANNAnnonceListe(DBManager, $routeParams) {
var ici = this;
this.annonces_ar = [];
this.idLieu = $routeParams.idLieu;

DBManager.all('ANNAnnonce')
    .then(function (annonces) {
        console.log(annonces);
        ici.annonces_ar = annonces;
    })
    .catch(function (error) {
        console.log(error)
    });
}

the second here :

<div ng-repeat="(key, value) in vm.annonces_ar | filter: {value.id : vm.idLieu_nb} ">
    {{value.nom_str}}
    {{value.idLieu_nb}}
</div>

i would like this equality (vm.idLieu = value.id_nb) and display if is true

Thanks.


Solution

  • It should be property name directly id_nb instead of value.id. Also have : true parameter at the end of your filter to perform exact check, inspite of contains check.

    <div ng-repeat="(key, value) in vm.annonces_ar | filter: { idLieu_nb : vm.idLieu}: true ">
        {{value.nom_str}}
        {{value.idLieu_nb}}
    </div>