How can I activate div elements by clicking on a specific div using Angular 2?

I have created a custom component with search dropdown functionality for selecting dates.

<div class="search-dropdown calender-dropdown ">
   <div class="search-dropdown-tabs-wrp">
      <ul class="search-dropdown-tabs">
         <li>
            <a class="search-dropdown-tabs-active">Today</a>
         </li>
         <li>
            <a>Tomorrow</a>
         </li>
         <li>
            <a>This weekend</a>
         </li>
         <li>
            <a>This week</a>
         </li>
         <li>
            <a>Next week</a>
         </li>
         <li>
            <a>This month</a>
         </li>
      </ul>
   </div>
   <div class="tab-content-area">
      <ul class="tab-content-area-active">
         <div class="row">
            this is the first tab
         </div>
      </ul>
   </div>
</div>

component.ts

import { Component, Output,EventEmitter} from '@angular/core'; 
@Component({
    moduleId:module.id,
    selector: 'calendar',
    templateUrl: './calendar.component.html'
})
export class CalendarComponent{
   @Output() onDatePicked: EventEmitter<any> = new EventEmitter<any>();  
  public fromDate:Date = new Date();    
  public toDate:Date = new Date();
  public closed : boolean;
  private events:Array<any>;
  private tomorrow:Date;
  dates = { startDate: this.fromDate, endDate: this.toDate , closed : this.closed};
  private afterTomorrow:Date;
  private formats:Array<string> = ['DD-MM-YYYY', 'YYYY/MM/DD', 'DD.MM.YYYY', 'shortDate'];
  private format = this.formats[0];
  private dateOptions:any = {
    formatYear: 'YY',
    startingDay: 1
  };
  private opened:boolean = false; 

  public pickDate( ): void {
    this.dates = { startDate: this.fromDate, endDate: this.toDate , closed : false};
    this.onDatePicked.emit(this.dates);
 }   
  public closeComponent() : void{
    this.dates.closed = true;
  }

Is there a way to activate the 2nd tab content when Tomorrow is clicked?

Answer №1

component.ts

import { Component, Output,EventEmitter} from '@angular/core'; 
@Component({
    moduleId:module.id,
    selector: 'calendar',
    templateUrl: './calendar.component.html'
})
export class CalendarComponent{
   @Output() onDatePicked: EventEmitter<any> = new EventEmitter<any>();  
  public fromDate:Date = new Date();    
  public toDate:Date = new Date();
  public status: string = "today"
  public closed : boolean;
  private events:Array<any>;
  private tomorrow:Date;
  dates = { startDate: this.fromDate, endDate: this.toDate , closed : this.closed};
  private afterTomorrow:Date;
  private formats:Array<string> = ['DD-MM-YYYY', 'YYYY/MM/DD', 'DD.MM.YYYY', 'shortDate'];
  private format = this.formats[0];
  private dateOptions:any = {
    formatYear: 'YY',
    startingDay: 1
  };
  private opened:boolean = false; 

  public pickDate( ): void {
    this.dates = { startDate: this.fromDate, endDate: this.toDate , closed : false};
    this.onDatePicked.emit(this.dates);
 }   
  public closeComponent() : void{
    this.dates.closed = true;
  }

component.html

<div class="search-dropdown calender-dropdown ">
        <div class="search-dropdown-tabs-wrp">
            <ul class="search-dropdown-tabs">
                <li>
                    <a (click)="status='today'" class="search-dropdown-tabs-active">Today</a>
                </li>
                <li>
                    <a (click)="status='tomorrow'">Tomorrow</a>
                </li>
                <li>
                    <a>This weekend</a>
                </li>
                <li>
                    <a>This week</a>
                </li>
                <li>
                    <a>Next week</a>
                </li>
                <li>
                    <a>This month</a>
                </li>
            </ul>
        </div>
        <div class="tab-content-area">
            <ul class="tab-content-area-active" *ngIf="status=='today'">
                <div class="row">
                   this is the first tab
                </div>
            </ul>
            <ul class="tab-content-area-active" *ngIf="status=='tomorrow'">
                <div class="row">
                   this is the second tab
                </div>
            </ul>
        </div>
</div>

Utilize a variable to control what content gets displayed. For example, you can set (click)="state='tomorrow'". Then in your template, use *ngIf to show or hide certain sections like *ngIf="state=='tomorrow'".

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

Struggling to connect JSON information to a dynamically loaded sub-component

I'm currently working on dynamically loading a child component from the parent component. The goal is to pass some parameters from the parent to the child, which will then be used in the child component to make a service call and retrieve data from a ...

Tips for Promoting Content Using Offcanvas Navigation Menu

I am currently working on an Angular 12 project that incorporates Bootstrap 5 and NGX-Bootstrap. I am interested in developing a side navigation bar that is initially active but can also be collapsed. I wonder if this could be achieved using the Offcanvas ...

How can I add a new key value pair to an existing object in Angular?

I'm looking to add a new key value pair to an existing object without declaring it inside the initial object declaration. I attempted the code below, but encountered the following error: Property 'specialty' does not exist on type saveFor ...

Caution: The `id` property did not match. Server: "fc-dom-171" Client: "fc-dom-2" while utilizing FullCalendar in a Next.js environment

Issue Background In my current project, I am utilizing FullCalendar v5.11.0, NextJS v12.0.7, React v17.0.2, and Typescript v4.3.5. To set up a basic calendar based on the FullCalendar documentation, I created a component called Calendar. Inside this comp ...

Displaying array elements on a webpage using JavaScript in HTML

Looking to display multiple blocks in HTML using a JavaScript array. The array contains names such as: var name=['amit','mayank','jatin'];. I need to repeat a certain portion of code in order to show the elements of the array, ...

Responsive design and column alignment dilemma

I'm attempting to create a layout using Bootstrap 3.2.0 with tiled divs in a single row for screens wider than 768px. The divs have heights of either 50px or 100px, controlled by the classes "home-height-single" and "home-height-double," and widths ad ...

"Encountered an error: 'Invalid private class xy' in the process of constructing an Angular library

Currently, I am in the process of creating an npm package using Angular. In the midst of building the library, I encountered the following error: An unexpected issue with the private class MyLibComponent has surfaced. While this class is accessible to us ...

Two headings using the same tags appear distinctively rendered

Recently, we added an iframe to our company's website that I have been helping manage. This iframe is responsible for handling requests sent to our organization. Interestingly, the headings on our website are styled using the following CSS: color: # ...

Tips for reducing the amount of white space on a card featuring a pie chart in a mobile layout

Is there a way to adjust the size of the pie chart or reduce the white space at the bottom? In the mobile view after inspecting with Chrome dev tools, it seems like the chart is not displaying as desired. Here is the screenshot <div ...

Is there a way to locate a model using a value within a OneToMany connection?

I am trying to develop a function to retrieve a user model based on a specific value within a OneToMany relationship. Below is the function in question: async getUserViaPlatform(provider: string, id: string) { return await this.webUserRepository. ...

Component presenting surprising results

Struggling to display data in an HTML component, I encountered a peculiar issue. Upon entering values for the first time, everything appears correctly. However, upon subsequent entries and retrievals, the second value is displayed twice, the third value th ...

Tips for incorporating Angular-specific code into Monaco Editor

I am currently developing a browser-based IDE using the Monaco editor. I'm allowing users to input Angular-specific code into the editor, like this: import { Component } from '@angular/core'; @Component({ selector: 'app-root', ...

Ways to expand the height of content using grid?

I'm having trouble getting my grid template to stretch content to the end using CSS Grid. The behavior is unexpected, and I want to create a Jeopardy game where clicking on a box reveals a question. Initially, I applied display: grid to the body elem ...

How can I align a button right next to the table row data in HTML using Bootstrap?

Is there a way to add a button next to the table data in each row without a border? I attempted to create a new column for the button, but the border interferes with the design. I am using Bootstrap 4 for this project. Here is the HTML code: <div cl ...

Fluid image background failing to display properly in Firefox browser due to CSS compatibility issues

I'm currently working on implementing a fluid image background for one of my webpages. It's functioning perfectly in Chrome, but I can't seem to get it to work in Firefox. The goal is to have two squares with PNG images that resize proportio ...

What steps should I follow to set up a dynamic theme in an Angular Material application?

I have spent countless hours trying to find clear documentation on setting up an Angular Material app with a theme, including changing the theme dynamically. Despite searching through numerous search results and visiting various pages, I have not been able ...

How can certain HTML be redirected or hidden for users on mobile devices?

Lately, I've been putting the final touches on my website to present to potential employers as I will soon be starting my job search after graduation. I recently added an "about" section with parallax scrolling effect, but unfortunately, it's not ...

The issue encountered is when the data from the Angular form in the login.component.html file fails to be

I am struggling with a basic login form in my Angular project. Whenever I try to submit the form data to login.components.ts, it appears empty. Here is my login.component.html: <mat-spinner *ngIf="isLoading"></mat-spinner> & ...

Step-by-step guide on activating a button only when all form fields are validated

My very first Angular 5 project. I've gone through resources like: https://angular.io/guide/form-validation and various search results I looked up, only to realize that they are all outdated. In my form, I have several input fields such as: <for ...

Generate a loop specifically designed to execute the code following the menu in the script

My website has the code snippet below: let txt_com = document.querySelector(".text_user"); let num_com_user = document.querySelector(".massage_for_user"); txt_com.addEventListener("click", function() { if (this.classList.contains("num_com_user")) { ...