Ways to display the md-card content based on the selected item in Angular2

1. I have 3 categories: ALL, Images, and Videos.

  1. When I select ALL, I want both videos and images to display in two separate cards.
  2. If I choose either Image or Video, only that specific type of content should be displayed.

https://i.sstatic.net/4ezDw.png

Under the All category, there are a total of 5 items - 3 images and 2 videos. I expect the 3 image items to be shown in the image section and the 2 video items in the video section. Currently, all 5 items are displayed in both sections when selecting All. Here is how it currently appears for the All category: Now, if I click on Images, I want only the image section to be displayed in full page rather than split into 2 cards.

HTML:

<div class="row">
    <div class="container-fluid col-lg-12 col-md-12 col-sm-12 col-xs-12" style="padding:0px 20px 30px;">
        <md-card style="margin:10px -14px;float:left;padding-top:0px!important;padding-bottom:20px!important;" class="border-top-3px col-lg-6 col-md-6 col-sm-6 col-xs-12 taskDiv width49">
            <md-card-title style="margin-bottom: 25px;">
                <h3 class="color-primary" style="margin: 2px 0px 2px 5px;letter-spacing: 0.6px;font-size:20px;color: #55595c;">Images</h3>
            </md-card-title>
            ...
        </md-card>
        <md-card style="margin:10px 0;float:right;padding-top:0px!important;padding-bottom:20px!important;" class="border-top-3px col-lg-6 col-md-6 col-sm-6 col-xs-12 taskDiv width49">
            <md-card-title style="margin-bottom: 25px;">
                <h3 class="color-primary" style="margin: 2px 0px 2px 5px;letter-spacing:0.6px;font-size: 20px;color: #55595c;">Videos</h3>
            </md-card-title>
            ...
        </md-card>
    </div>
</div>

Ts:

this.guideImage = [
    {label:"All",value:"all"},
    { label:"Images",value: "img" },
    { label:"Video", value: "video" },
  ];
  this.selectedImage="all";

Answer №1

Implement a switch between cards using *ngIf and logical operators.

Here's a simple example:

<mat-form-field>
    <mat-select [(value)]="selected">
        <mat-option value="1">All</mat-option>
        <mat-option value="2">Images</mat-option>
        <mat-option value="3">Videos</mat-option>
    </mat-select>

</mat-form-field>
<mat-card *ngIf="selected==='1' || selected==='2'">Images card</mat-card>

<mat-card *ngIf="selected==='1' || selected==='3'">Videos card</mat-card>

See it in action here

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 best way to position these two images side by side in a row?

Is there a way to place both images in the same row while also adding subtitles to each? I've tried different approaches, but I can't seem to align them properly with the subtitles included. <div class="container row-info"> <div cla ...

When adjusting the top margin of the main content in CSS, the fixed top navigation section's margin also decreases simultaneously with the main content

I am in the process of creating a basic static blog page using HTML5, SASS, and CSS. While working on the design, I utilized the 'nav' semantic element for a fixed top bar on the page that remains visible even when scrolling down. Additionally, ...

Extracting the date from an HTML file and transferring it to a PHP script, then storing it

Can you assist me in finding the necessary PHP code to insert the date from an HTML form into a database? The date format I am working with can be found here. HTML FORM: <form action="insertleave.php" method="post"> <label>Date Filed:& ...

How can you automatically adjust the height of a div to be 100% of its parent while maintaining top and bottom margins

http://jsfiddle.net/YumHS/ The page showcased in the provided jsfiddle link includes a sidebar within the content div. <section class="cont"> <div class="sidebar"> <ul> <li> ...

Using CSS to break or wrap long words in text

I have a div that spans the width of the page. I'm looking to ensure that a very long word in this div breaks and wraps properly, so all the content stays within the screen width and doesn't overflow beyond 100%. Although I've attempted usi ...

Updated INNER header and footer - unrelated to the answered questions

After observing, the inner-header and inner-footer div scroll along with the area that contains the select list. How can I make that area scroll down while keeping the inner-header/footer fixed within the content? I hope my query is understandable. Thank ...

Formatting styles for child components' templates using Angular's parent component CSS styling

Is there a way to override CSS of a child component from the parent using ::ng-deep or another method? In my parent component, I have included a child component like this: ....parent.component... <app-likes></app-likes> .....parent.component.. ...

What is the best method for implementing border-radius on select2 elements?

I previously had a default bootstrap user select box with a border-radius style applied: <div class="container"> <select class="form-control" style="border-radius: 1rem;"> <option value="1">Us ...

Could it be that the lower right corner of the border has vanished?

Some items in my list have borders on the left and right sides, but I am experiencing unexpected white gaps only on the right side. I have been unable to identify the issue despite going through my code multiple times. Any assistance would be highly appre ...

"Utilizing Bootstrap for a Dynamic Display: Implementing Multiple Carousels with Multiple Images within

I have incorporated several Bootstrap carousels on one page, each with its own unique identifier. These carousels are generated dynamically based on user interactions, such as uploading images. My goal is to display 3 images at once in each carousel. I am ...

What methods can I use to prevent a user from accidentally double clicking a link within an email?

After users request a password reset, they are sent an email containing a link to create a password reset code. This link remains valid for 24 hours and can be utilized multiple times within that time frame to generate new codes in case the initial one is ...

Leap over in a similar fashion to the provided demonstration

In my attempt to create a unique project, I have created this CodePen example. The goal is to have one ball on the circle that remains in a fixed position, while another rotating main ball must avoid touching it at all costs. Points are awarded for success ...

Troubleshooting Problems with Cascading Style Sheets

Struggling with a layout issue on my website. I need to display an image with text at the beginning of the site-wrap div under the name background-image, with the text inside that div. Adding line-height to the text div adjusts its height, but I want to m ...

Enhancing jQuery Mobile listview with voting buttons on each item row

I am looking to incorporate 2 vote buttons within a jQuery mobile listview, positioned on the left-hand side and centered within each list item. While I have managed to achieve this using javascript, my goal is to accomplish it without any additional scrip ...

A guide on using hyperlinks to scroll to a targeted position in an Angular application

Is there a way to implement scrolling to a specific position in Angular using hyperlinks? In HTML, it can be implemented like this: <a href="#google"></a> <div id="google"></div> Can anyone provide guidance on h ...

Only half the time does TranslateService.use() function properly with ngx-translate

My application is designed to fetch localization information from the backend using an observable within a localization module. constructor(translate: TranslateService){ locale.subscribe(fetched_lang => translate.use(fetched_lang) ); } The iss ...

Setting a custom background image in a Bootstrap modal

When users visit my website, I want to enhance their experience by using a background image in my bootstrap modal. Despite several attempts, I have been unable to successfully set a background image in the modal. Can anyone provide guidance on this matter? ...

Combining Django and Vue.js for efficient module importing

Is there a method to bring in modules for a VueJS app within a template, rendered by Django? I'm specifically looking to import the CKEditor module. This is my current setup: template.html: <div id="app"> <form> <vue ...

What is the best way to adjust the dimensions of a blank image without altering the size of

I am attempting to set the size of an empty image to 150px. While using float: left works on Firefox, it does not have the same effect on Google Chrome. Here is the HTML code: <div> <img src='some broken url' alt='no image'& ...

What is the best way to dynamically insert a directive element between an already existing parent directive and its child directive?

Background: Working within the constraints of a custom CMS that limits access to the code base, I am exploring the option of using JavaScript for DOM manipulations in certain scenarios. Problem: The issue I am facing involves a container directive conta ...