Customize ng-repeat lists by filtering elements based on another ng-repeat list

With only one array displaying titles, descriptions, and categories, the challenge arises when users can add their own categories. To showcase all categories and items, I utilized ng-repeat. The aim is to filter items using two filters: a text input for title filtering (which works well) and category buttons (currently not functioning).

The ng-repeat for categories is structured as follows:

<div class="list_categories">
 <label ng-click="clearAll()" ng-repeat-start="x in categories" ng-if="$first">
   <input type="radio" id="optradio" name="optradio" ng-model="searchCategory.Category" value="{{x}}" checked="checked">
   <p>{{x}}</p>
 </label>
 <label ng-click="clearAll()" ng-repeat-end ng-if="!$first">
   <input type="radio" id="optradio" name="optradio" ng-model="searchCategory.Category" value="{{x}}">
   <p>{{x}}</p>
 </label>
</div>

The ng-repeat for items looks like this:

<div class="card" ng-repeat="x in items | filter:searcher | filter:searchCategory" >
  <div class="title-space">
    <h2>{{x.Title}}</h2>
  </div>
  <div class="description-space">
    <p>{{x.Description}}</p>
  </div>
</div>

A functional example of the code can be found on this Plunker. Assistance is needed to get the Categories filter working properly.

Answer №1

Utilize ng-checked to manage the selection of the initial option.

<label ng-click="clearAll()" ng-repeat="x in categories">
    <input type="radio" id="optradio" ng-model="searchCategory.Category" name="optradio" ng-value="{{x}}"  ng-checked="$first">
   <p>{{x}}</p>
</label>

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

Utilizing a JavaScript class method through the onchange attribute triggering

I am facing an issue with a simple class that I have created. I can instantiate it and call the init function without any problems, but I am unable to call another method from the onchange attribute. Below is the code for the class: var ScheduleViewer = ...

Generate a div dynamically and incorporate a function that triggers on click event dynamically

In my current project, I am faced with a challenge due to laziness. My goal is to automatically generate menu buttons that are linked to different sections of a page using raw JavaScript. The issue arises when the body content of my site is loaded from an ...

Adapt the stylesheet for mobile devices using CSS

I am struggling with updating file paths in CSS depending on whether the end user is accessing my site from a PC or mobile device. Below is my CSS code, where I attempted to redirect users if they are on a handheld device: <link rel="stylesheet" type=" ...

mobile input sliders for selecting ranges

While working on a custom audio player, I encountered an issue with the default html5 input range object. Everything else seems to be working perfectly, with all events firing as needed, except for a frustrating problem on mobile Safari with iOS 11.4: Whe ...

Manipulating Strings in JavaScript Arrays

I am working with an array of arrays of data that is being retrieved from a csv file. My goal is to filter out specific indexes of an array based on the titles they contain. For instance: If an array index includes the title "Retail", I want to return the ...

Error encountered while parsing a file: JSON parsing failed due to an unexpected token 'g' at position

https.get('example.com/phpfilethatechoesandimtryingtograbtheecho.php', (res) => { console.log('statusCode:', res.statusCode); onsole.log('headers:', res.headers); res.on('data', (d) => { return ...

How can I activate deep linking from the address bar within a Node.js and AngularJS implementation?

Recently, I set up a NodeJS + ExpressJS server to handle routing and content delivery for an AngularJS application. The setup has been working well, with the routing functioning properly within the app itself. However, I encountered an issue when trying to ...

Is there a way to stop the automatic triggering of the form submit action?

This form has an action event that triggers when a button is clicked. <form id="prefForm4" enctype="multipart/form-data" method="post" class="masters" action="/Preferences/Preferences/RISSave"> </form> There are two buttons in this form, ...

What is the best way to automatically load and run every JavaScript file within a specific folder?

I am in the process of developing a straightforward content management system using JavaScript. The system relies on plugins that are stored as individual .js files within a designated "modules" folder. At present, I am utilizing jQuery's getScript() ...

Determine if the html element is wrapping to a new line when zoomed in or when the text size on Windows is increased

My webpage has 2 labels displayed side by side, but due to the system text size being set at 150% (which is recommended) in Windows, the second label does not have enough space and gets pushed below the first label. I am looking for a way to determine if t ...

Sending form data using Ajax in codeigniter

I am encountering an error while attempting to submit a form using ajax in codeIgniter. Below is the view code that I have: <div class="form-group input-control"> <p id="error1" style="display: none; color: green"><b>Registered Succ ...

Enhancing Angular input validators with updates

Working on a project with Angular 6, I have set up an input field using mat-input from the Angular Material framework and assigned it an id for FormGroup validation. However, when I initialize my TypeScript class and update the input value, the validator d ...

Aggregate array based on specified criteria in ReactJS

Let's consider the following array data: array = [ { id: 1, count: 0.5 cost: 100 user: {id: 1, name: "John 1"}, type: {id: 1, name: "T1"}, period: {id: 1, name: "2021"} ...

The 'this' variable is malfunctioning when trying to assign a JSONP array to an AngularJS controller

I'm working with a REST service in my angular controller and using JSONP to make the call. I need to store the array that is returned from the service into a variable. This is what I currently have: this.testTheRest = function() { $http.jsonp(&a ...

Transform the infoBox into a jQuery dialog modal window

In this section, I have integrated a map with markers and infoBoxes. My goal now is to replace the infoBoxes with jquery dialog() and modal window functionalities. How can I achieve this effectively? Below is the code snippet that includes the implementat ...

What is preventing me from looping through a class's prototype?

Looking for some help with this code snippet: class example {b(){}} for(const b in example.prototype) console.log(b) Curious as to why the methods inside example.prototype are not logging. I've debugged it and can see them there. This is for ...

Animating nested ng-repeat loops

Trying to animate a list of elements divided by rows (the parent ng-repeat) and columns (the child ng-repeat) has been quite challenging. While I was able to achieve the desired animation with individual ng-repeats, the same cannot be said for nested ng- ...

Troubleshooting React/Jest issues with updating values in Select elements on onChange event

I am currently testing the Select element's value after it has been changed with the following code: it("changes value after selecting another field", () => { doSetupWork(); let field = screen.getByLabelText("MySelectField") ...

Using v-model with an input file is not supported

Is there a solution for not being able to use v-model in an input tag with type="file"? Here is an example of the HTML code causing this issue: <input v-model="imageReference" type="file" name="file"/> ...

Using Vue.js's computed property to dynamically bind a class in v-bind

I am familiar with using v-bind:class when returning true or false from a computed function. I am curious to know if it is possible to use a computed property that matches the ID and value of a button being clicked. For example, clicking button 1 would al ...