Transfer information from one part to another part

I currently have a calendar feature with a modal window that allows users to add events for any day on the calendar. I am able to write data to the console, but I am struggling to bind it in order to save the written data to the calendar cells.

If you'd like to take a look at my code, you can find it here: https://stackblitz.com/edit/angular-nxczn8

My goal is to display the saved event data in the calendar cell when the "save event" button is clicked. How can I achieve this?

Answer №1

I have successfully resolved the issues you were facing. In order to display events when the month changes, it is necessary to store this information either in your service or component. You can also refer to the updated StackBiltz

in your app.component.ts file

weeks: Array<Array<{date: Date, hasEvent: boolean, eventTitle: string}>>;

  getEvents() {
    this.calendar.setDate(this.date);
    console.log(this.calendar.getWeeks());
    this.weeks = this.calendar.getWeeks().map(x => { return x.map(y => { return {date: y, hasEvent: false, eventTitle: ""} }) });
    const from = this.calendar.getFrom();
    const to = this.calendar.getTo();
  }

  openModalContent(weekIdx, day) {
    const  modalRef = this.modalService.open(ModalContentComponent);
    modalRef.result.then((result) => {
      day.hasEvent = true;
      day.eventTitle = result;
      console.log("result -> ", result);
    }).catch((error) => {
      console.error(error);
    });
  }

in your app.component.html file

<tbody>
<tr *ngFor="let week of weeks; let weekIdx = index">
  <td *ngFor="let day of week" class="day-of-month" [ngClass] = "{'bg-primary': day.hasEvent}">
    <div class="events">
      <span class="day-number">{{ day.date | date:'d' }}</span>
      <button (click)="openModalContent(weekIdx, day)" class="btn-add">Add event</button>
    </div>
  </td>
</tr>
</tbody>

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

RxJS - BehaviorSubject does not trigger onComplete callback

I've been developing an Angular 7 application and using BehaviorSubject to manage the user authentication state, following the widely recommended practice from various sources online. However, I've come across a puzzling issue - given that Behav ...

Dynamic linking of tab pages in Ionic 2 using the root function

One interesting feature in Ionic 2 is the ability to dynamically create tabs using JSON responses. By linking these tabs with their corresponding pages dynamically, we can enhance user experience. Here's a code snippet that demonstrates this: <ion ...

What is the process for defining the default landing page route in Angular routing?

My application currently has only one route, and I want it to start with the URL http://localhost:4200/specialtyQ. However, my application is not loading properly. The code snippet below is what I am using to try to achieve this. How can I correct the URL ...

An argument of type 'Array<T>' necessitates the inclusion of one type argument

I've come across this issue multiple times on various online forums. Despite trying different solutions, I'm still unable to resolve the following error: (11,23): Generic type 'Array' requires 1 type argument(s). This pertains to t ...

Tips for synchronously reading a line from the console using ts-node

Currently, I am developing a node.js application using typescript which displays a menu on the console and prompts the user for input ranging from 1 to 5. To display the menu, I can utilize console.log(). console.log('1: Option#1'); console.log ...

Issues with retrieving data using Angular's http.get

I have set up a basic Rails5 API and I am currently attempting to retrieve data from the API within my Angular application. When I navigate to: http://localhost:3000/movies, I receive the following response: [{"id":2,"title":"Batman","created_by":"1"," ...

Is there a way to run an observable only once?

Within our project, we have implemented a specific approach: instead of retrieving the value from the observable, we directly add the value to the store. See the code snippet below for an example: loadReport() { return this.http.get(url, { params: ht ...

The versatile payment solutions offered by PayPal, including Adaptive Payments and Chained Payments, can be seamlessly

At this time, PayPal Adaptive Payments has been flagged as deprecated and there is no available frontend documentation. I have not been able to find a way to achieve this using the existing documentation. I am currently developing an Angular app that inte ...

Encountered issue: The type 'Teacher[]' cannot be assigned to the type 'Teacher'

I am currently working on enhancing my angular application by adding a new service. However, I have encountered an error that I need help fixing: The error message states: Type 'Teacher[]' is not assignable to type 'Teacher'. Property ...

The generated code is unable to import the file compiled by Clasp

I am encountering an issue with my TypeScript files in my Google App Project. Here is a breakdown of my files: src/main.ts function main(): void { console.log('main'); hello(); } src/other.ts console.log('hello world'); ...

Unable to access @ViewChild in Angular Google Charts, encountering the error message "chart is undefined"

Struggling to access the underlying ChartWrapper following the provided instructions at https://github.com/FERNman/angular-google-charts#advanced. Unfortunately, encountering an error stating "Chart is undefined." Attempted swapping ngOnInit() with other ...

How to set up scroll restoration for the Angular Standalone Router?

The Angular Router provides the option to restore scrolling functionality, with documentation on how to implement it when loading data. Is there a way to configure the standalone router to automatically scroll back to the top of the router outlet? A demo ...

Angular 2: Understanding the Initialization Process

I've thoroughly searched the documentation and I can't seem to find a detailed breakdown of the step-by-step procedure that occurs during bootstrap. Here's an outline of what I'm looking for: Collection of all modules Instantiation o ...

Display or conceal an icon based on the data in the field

Can someone provide guidance on how to make an icon appear or disappear based on the logic within [ngIf]? The icon should only be displayed if there is information in a specific field. Should I implement this inside ngIF or in my TS file? Can the icon cl ...

Disabling aria-label enforcement for icon-buttons in Chakra UI Typescript

Having a Chakra UI icon button, I am facing an issue with the aria-label attribute. The IconButton is within an aria-hidden section in the tree; therefore, the label becomes redundant. If I try to remove the aria-label, TypeScript throws complaints as sho ...

Is the table state not supported for reordering columns within the table component?

I am currently using version 12.2.3 of PrimeNg along with the p-table component. I have successfully managed to resize and reorder columns in the table. However, I am facing an issue when trying to save the table state. Once I enable the feature to save th ...

Retrieving the chosen option from a personalized drop-down element

I have been working on a project using Angular 2, where I created a dropdown component with the following code: @Component({ selector: 'dropdown', template: ` <div class="row" > <div class="col-sm-3"> ...

When utilizing Angular2+ InMemoryWebAPI, SVG icons may not load properly

During the setup of InMemoryWebAPI, I encountered an issue where SVG icons were not loading properly. @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, FormsModule, ReactiveFormsModule, HttpClientModule, H ...

What is the best way to detect component errors on the server with Angular Universal?

Here is a snippet of my server code that renders the Angular home.component: app.get("*", (req, res) => { res.render( `../${CLIENT_DIST_DIR}/index`, { req: req, res: res, providers: [ ...

What is the best way to dynamically adjust the size of a table or div when clicking in Angular 2?

Is there a way to dynamically resize a table or div in Angular 2 by clicking on a button or other element? I am attempting to change the width of a table from 300px to 100px using a function that utilizes CSS and TypeScript. table{ width: 300px; res ...