Do not include objects in the search results that lack necessary information

My ng-repeat code looks like this:

<div layout="row" flex layout-wrap layout-margin layout-padding>
     <tile ng-repeat="camp in ctrl.camps | filter:{ctrl.search} track by $index"></tile>
</div>

The ctrl.camps object array is structured as follows:

{
  "id": 1,
  "name": "Hey!",
  "kind": "Something",
  "variation": {
      "type": "Smarty",
      "color": "Blue",
   }
},
{
  "id": 2,
  "name": "More Heys!",
  "kind": "Another thing",
  "variation": {
      "type": "Smarty",
      "color": "Green",
   }
},
{
  "id": 3,
  "name": "Hey!",
  "kind": "my kind",
  "variation": {
      "type": "Smarty"
   }//  This one doesn't have a color!
}

Note that the entry with id: 3 does not have a variation color.

I have set up an md-select for filtering, shown below:

<md-input-container>
    <label>Variation color</label>
    <md-select ng-model="ctrl.search.variation.color">
         <md-option ng-click="!null">Empty option</md-option> //I want to be able to clear this selection with the ng-click.. Not sure how.
         <md-option ng-repeat="color in ctrl.colors" value="{{color}}">{{color}}</md-option>
     </md-select>
 </md-input-container>

Although the filtering works well, there is an issue when trying to clear the filter using the empty option. The variation without a color does not reappear after selecting the empty option. Does anyone know how to fix this so that all objects are displayed again upon clearing with the ng-click? Thank you.

Answer №1

I encountered a similar issue to yours.

To resolve it, you need to clear the 'search' object.

Once your md-select is emptied, it will appear like this:

{
  "variation": {color:""}
}

The Filter-model checks if the element has any value for variation.color.

You can add a function to ng-change that verifies if search.variation.color is empty. If so, remove it using delete search.variaton.color or utilize $watch on $scope.search.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unlocking the Secrets of Launching a Modal with Javascript

I currently have an HTML code that includes a fabulous floating button. When I click on this button, I would like to open a modal popup window but unfortunately, I am unsure of how to achieve this. index.html <html> <head> <link rel="s ...

The onsubmit function is not functioning correctly in combination with Ajax

My current implementation involves utilizing Ajax and Php for user login validation. Unfortunately, the form onsubmit function is not properly functioning. <form action="loggedin.php" onsubmit="return test()" method="post"> Below is the correspondi ...

Issue encountered with search.run().getRange function when accessing a stored search in suitescript 2.0

I am facing an issue with my saved search in the beforeLoad userevent script. After adding a filter and running the search, Netsuite throws an UNEXPECTED_ERROR. Any ideas on what might be causing this error? var poRec = context.newRecord; var countIt ...

Gracefully Switching Between Various Functions

Suppose I have a collection of functions that perform various tasks: function doSomething() { console.log('doing something'); } function accomplishTasks() { console.log('accomplishing tasks'); } function executeAction() { console. ...

The display of HTML code bound with controller values in Angular 1.X is not appearing correctly

I am looking for a secure way to incorporate HTML with Angular content into my website. However, despite the HTML binding, the angular part is not displaying correctly. var app = angular.module('dashboardApp', ['ngSanitize']); app.con ...

Display or conceal the nearest element that was clicked

http://jsfiddle.net/KevinOrin/xycCx/1/ jQuery('.happening-main-text .readmore').click(function() { jQuery('.divmore').toggle('slow'); return false; }); ...

What is the best way to implement a sidebar closing animation?

Utilizing both react and tailwindcss, I successfully crafted a sidebar menu that elegantly appears from left to right when the user clicks on the hamburger icon. However, my attempts to create a reverse animation as the sidebar disappears from right to lef ...

Is there a bug in Safari 8.0 related to jQuery and backslashes?

I am using Mac OS 10.10 Yosemite and Safari 8.0. Attempting to read an XML (RSS) file: <content:encoded>bla bla bla</content:encoded> The Javascript Ajax method I am using is: description:$(valeur).find('content\\:encoded&apo ...

Extract all nested array object values in JavaScript without including a specific key value

I am looking for a way to remove a specific key value pair within a nested array object in JavaScript. The goal is to get all the objects in the array after the removal. Can someone help me with this? In the following object, I want to remove the mon key ...

The Express GET route does not support parameters or additional paths

I am facing an issue with making a fetch request when trying to add additional path or parameters... Here is what I want to achieve: const fetchOwnerCardList = () => { fetch("http://localhost:5000/api/card/ownerCards", { method: "GET", header ...

Testing the capabilities of AngularJS with e2e testing using the angular-recaptcha library

I have been attempting to e2e test my basic application, but I am facing challenges with the angular-recaptcha plugin from VividCortex (https://github.com/VividCortex/angular-recaptcha). Here is the test case I am working on: it('should redirect t ...

Trouble with submitting a form and showing a success message in AngularJS version 1.6.8

My query submission form consists of fields for name, email, and the actual query. The component includes a controller function with a submit function to handle form submission. To submit user input and display a success message upon submission, I utilize ...

Is there a way for me to retrieve $event within a directive?

I'm struggling to figure out how to pass it as an attribute! Although I can use ng-click="function($event)" to pass $event to a controller function, I really want to access it within a directive. My main goal is to be able to stopPropagation() and/o ...

React Native: Once a user has successfully logged in, I would like the app to automatically direct them to the "Home" screen

After a user signs in, I would like my app to navigate home. However, it seems this is not working because the roots have not been updated. You can view the App code here to get a better understanding of what I am trying to communicate. What is the most e ...

When an input is submitted, the keyword will default to the corresponding hex code in JavaScript

When searching for the color 'blue', the system displays palettes for "BLUE" instead of 'blue'. The issue seems to be related to the on submit function, and I am struggling to find a solution. If I remove the 'color' class fr ...

Rotating around the midpoint of a manipulator in Three.js

Despite asking a similar question recently, I am still struggling to figure out how to properly set the center of a three js control in order for it to rotate as intended. I have come across various examples involving geometry, bounding boxes, pivot points ...

Adding external stylesheets or libraries in Express is a simple process that can greatly

Currently, I am in the process of developing a todo application using the express framework on a node server. The starting point for my application is an index.ejs file located in the same folder as my jquery.min.js file. However, when I attempt to include ...

The HTML changes are not reflected in the document.querySelectorAll function

Trying to select all the div elements within another div using document.querySelectorAll. Interestingly, when setting the height to 1000 in the JS, the browser's scrollbar adjusts accordingly (the balloons do not change size). What could I be doing in ...

Employ the 'this' attribute within _.map

I am facing an issue where I need to call a setState function within a _.map loop in React. However, the loop is losing the reference to 'this' and therefore I cannot use setState as this becomes undefined. cargaDinamica(){ _.map(this.stat ...

Unable to use console log in shorthand arrow function while working with Typescript

When debugging an arrow function in JavaScript, you can write it like this: const sum = (a, b) => console.log(a, b) || a + b; This code will first log a and b to the console and then return the actual result of the function. However, when using TypeSc ...