Filtering an array with radio buttons in Angular

I am working with a JSON list that contains various audio files categorized by genre, along with their corresponding URLs.

export const musicList = [
  {
    'id': 0,
    'catName': 'upload',
    'audios': [
      {
        'id': 0,
        'name': 'crowd-cheering.mp3',
        'path': 'a.com/music.mp3'
      }
    ]
  },
  {
    'id': 1,
    'catName': 'rock',
    'audios': [
      {
        'id': 1,
        'name': 'Consectetur',
        'path': 'a.com/music.mp3'
      },
      {
        'id': 2,
        'name': 'Vivamus',
        'path': 'a.com/music.mp3'
      }
    ]
  },
  {
    'id': 2,
    'catName': 'folk',
    'audios': [
      {
        'id': 1,
        'name': 'Suspendisse',
        'path': 'a.com/music.mp3'
      }
    ]
  }
];

To display these music files, I am using *ngFor like this:

<div *ngFor="let music of musicList">
  <div *ngFor="let audio of music.audios"> 
    {{audio.name}}
  </div>
</div>

Additionally, I am listing the categories with radio buttons as well:

<div *ngFor="let category of musicList">
  <input type="radio" name="genre"> {{category.catName}}
</div>

Now, I would like to implement a filter option. When a user selects a radio button, the list should display only the audio files related to the selected category.

Angular CLI: 6.0.8
Typescript : 2.7.2

Answer №1

Utilize the ng-change feature to execute a function that includes the specific filter you desire

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

What is the process for inserting a document into an array that is nested within another array?

My current dilemma revolves around a document (referred to as 'root') which contains an array of other documents ('stick'), each of which in turn contain another array of documents ('leaf'). Simply put: root{ stickChain[leaves ...

Steps for eliminating curly braces and renaming the key-value pairs in a JSON object

I have a JSON output that looks like this: { "intent": "P&P_Purchase", "value1": { "date1": "30-Dec-19", "prd_desc": "NEEM UREA OMIFCO (45 KG)", "qty": &quo ...

Exploring Objects with Union Types in TypeScript

Looking to iterate through an object that combines two interfaces. interface Family { cat: string; age: string; family: string; lastYearFamily: string; } interface Model { cat: string; age: string; ...

Populate input fields in HTML using Angular 4

Within my angular 4 project, I am facing the challenge of setting a value in an input field and in a MatSelect without relying on any binding. Here is the HTML structure: <div class="row search-component"> <div class="col-md-5 no-padding-rig ...

Steps for eliminating the chat value from an array tab in React

tabs: [ '/home', '/about', '/chat' ]; <ResponsiveNav ppearance="subtle" justified removable moreText={<Icon icon="more" />} moreProps={{ noCar ...

Refine the Mapped Result

I'm a complete beginner and could use some help. Currently, I am utilizing pandas to read parquet files. Within my dataset, there is a column that contains mapped values. I want to filter the data based on this mapped value and only return rows that ...

How to Exclude Whitespaces from Strings in Angular 6 DataTables

I am facing a simple issue where I need to display strings with spaces like "st ri ng" in rows within a material data table. However, the spaces are being trimmed and I cannot figure out how to keep them intact. Here is a demo on stackblitz: https: ...

Obtaining an instance of the CKEditor Editor in TypeScript with CKEditor 4: what's the best way?

Can someone explain how to utilize the CKEDITOR 4 plugin in TypeScript for an Angular 9 application? I am looking to set the configuration through TypeScript (specifically for autogrow) and also implement an INSERT HTML function. I have already imported ...

Efficient method for updating objects in various arrays

I'm curious to find out whether modifying an object in one array will reflect the changes in other arrays. My array consists of various tasks, each represented by a hash object with keys such as 'id,' 'user,' and 'task.' ...

I am having trouble with a property that I believe should be recognized but is not

Here is the vocabulary I am working with: type MyHeaders = { Authorization: string; Accept: "application/json"; }; type MyGetOptions = { url: string; json: true; }; type MyOptionsWithHeaders = { headers: MyHeaders; }; type MyPostOptions ...

While utilizing Ionic to upload images to a server, I encountered the FileTransferError error code 3

I have successfully uploaded an image from the gallery, but I am facing issues while uploading multiple images at once. Here is the code snippet I am using: pictureUpload(x){ // x represents the file path like - file:///storage/emulated/0/Download/palak ...

Is there a way to merge TypeScript code with C++ during compilation?

Currently, I have a project written entirely in C++. However, there is an additional file written in typescript because I couldn't find equivalent libraries in C++. This typescript file performs the following actions: It contains a typescript CLI cod ...

Unable to utilize the "let" keyword in WebStorm

Currently, I am delving into learning typescript and attempting to create a simple 'let' statement. However, I encountered an error indicating the need to use ECMAScript 6 or later versions. The exact message from the typescript compiler states: ...

Navigating the inner component of an ng-template in Angular

Imagine a scenario where we have a component named TopComponent with a template structured as follows: <ng-template #top> <inner-selector #inner></inner-selector> </ng-template> The code for this component is quite straightforw ...

Is Angular 10 disregarding set-cookie response headers?

After logging in, I attempted to utilize a session auth cookie without success. To troubleshoot, I implemented a basic "CookieTest" method on my Dotnet Core server: [Route("CookieTest")] public ActionResult CookieTest() { var options = new CookieOptions ...

Issue with data not being recorded accurately in React app after socket event following API call

The Application Development I have been working on an innovative app that retrieves data from the server and visualizes it on a chart while also showcasing the total value in a Gauge. Additionally, the server triggers an event when new data is stored in t ...

Is the latest Swiper JS version compatible with outdated web browsers?

Seeking information on browser compatibility. I am interested in upgrading to the latest version 8.4.5 of Swiper JS for my project, currently using version 4.1.6. Upon examining their shared Github repository file .browserslistrc, I noticed changes that ta ...

Learning how to use RestSharp's POST method in C# to send JSON data

Currently, I am in the process of testing a REST API using RestSharp. To post data and receive status (error, invalid, success) based on callback, I need to use the POST method. However, I am encountering an INVALID response with the message "Object refere ...

Navigate to a new tab using this.router.navigate

Is there a way to redirect the user to a specific page with ${id} opening in a new tab, after clicking a button in an angular material dialog box? I want to leave the dialog box open while querying the new page. Currently, the redirect happens but not in a ...

Tips for effectively displaying a user's update or change

In my moments component, each moment is like a thread or post that users can like or dislike. When a user likes a moment, the momentService is called to retrieve the updated list and refresh the like count of that particular moment. However, updating all ...