0

I'm having a problem if it is not easy to solve ta. In my database I have a table in organizations and some of them may be "hidden". You may not see them on a list unless enter a unique code given by the administrator. If the user types the code only then that organization may appear in the list.

My list now looks like this:

<a class="item item-avatar" ng-repeat="lugar in organizations_all | filter:search" ng-click="mostrarAreas(lugar.id)" ng-if="organizations_filter !=''" ng-show="!lugar.hide">
  <img image-lazy-src="{{lugar.photo}}" style="border-radius: 0 !important;">
  <button class="button button-icon icon ion-plus-circled" ng-click="agregarLugar(lugar.id,lugar.private);$event.stopPropagation()" style="float: right;"></button>
  <h2>{{lugar.name}}</h2>
  <p class="icon ion-ios-locked" style="font-size:20px;"  ng-show="lugar.private"></p>
</a>

Y mi json viene asi :

{ "Count" : 5,
"Organization" : [ { "code" : "",
    "hide" : false,
    "id" : "1",
    "name" : "Odebret Advisors Ltda.",
    "private" : false
  },
  { "code" : "",
    "hide" : false,
    "id" : "2",
    "name" : "MOP Ruta 5 Sur (SCL - Talca)",
    "private" : false
  },
  { "code" : "",
    "hide" : false,
    "id" : "3",
    "name" : "MOP Ruta 5 Norte (SCL - Los Vilos)",
    "private" : false
  },
  { "code" : "",
    "hide" : false,
    "id" : "4",
    "name" : "Lixsys SpA",
    "private" : true
  },
  { "code" : "lxspa",
    "hide" : true,
    "id" : "5",
    "name" : "Prueba Oculta",
    "private" : false
  }
],
"status" : 1
}

As you can see, there is a "hide" field if true, must hide that organization and also a "code" field is the only code to find and must be entered FULL whereas if we filter by name, you can discriminate by 1 point on.

2 Answers 2

2

just use a && statment in the ng-show so

so for your search input if you have

ng-model="searchInput"

and in the controller you have

$scope.searchInput

then on the ng-show you can do

ng-show="!lugar.hide && lugar.code == searchInput"

Then it will only show them if hide is set to false AND if they have typed in the code. Or if you want to show it even if hide is true, but they typed in the code you can do

ng-show ="!lugar.hide || lugar.code == searchInput"
Sign up to request clarification or add additional context in comments.

2 Comments

not even work for me, I'm trying to adapt to my problem.
well I have used this multiple times in multiple apps and it does indeed work. have you used && || comparison and logic operators before?
1

EDIT: This is assuming that the code is contained in your filter:search parameter, since you didn't specify where the user is typing the code.

You'd be better off creating your own filter:

.filter('esVisible', function () {
  return function (lugares, search) {
    var lugaresVisibles = [];
    for (var i = 0, ii = lugares.length; i < ii; i++) {
      if (!lugares[i].hide) {
        lugaresVisibles.push(lugares[i]);
      } else if (lugares[i].code == search) {
        lugaresVisibles.push(lugares[i]);
      }
    }
    return lugaresVisibles;
  };
});

If you are using another JS utility library as well like LazyJS, you could probably simplify the for loop pretty easily.

In the end your ngRepeat would look like this:

ng-repeat="lugar in organizations_all | esVisible:search"

Note: Untested, but hopefully you get the idea.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.