An issue has occurred: the property 'map' cannot be read as it is undefined

Encountered this unexpected error and struggling to understand the reason behind it.. I've been attempting to showcase events on angular-calendar:

Error occurred in error_handler.ts:1 - ERROR TypeError: Cannot read property 'map' of undefined at MapSubscriber.project (planning.component.ts:100) at MapSubscriber._next (map.ts:75) at MapSubscriber.Subscriber.next (Subscriber.ts:95) at MapSubscriber._next (map.ts:80) at MapSubscriber.Subscriber.next (Subscriber.ts:95) at XMLHttpRequest.onLoad (xhr_backend.ts:99) at ZoneDelegate.webpackJsonp.85.ZoneDelegate.invokeTask (zone-mix.js:424) at Object.onInvokeTask (ng_zone.ts:280) at ZoneDelegate.webpackJsonp.85.ZoneDelegate.invokeTask (zone-mix.js:423) at Zone.webpackJsonp.85.Zone.runTask (zone-mix.js:191)

component.ts

import { Component, ChangeDetectionStrategy, OnInit } from '@angular/core';
import { Http, URLSearchParams } from '@angular/http';
import { HttpClient } from '@angular/common/http';
import { CustomDateFormatter } from './custom-date-formatter.provider';
import 'rxjs/add/operator/map';
import { Observable } from 'rxjs/Observable';

interface Event {
 id: number;
 title: string;
 start: string;
 end: string;
}

events$: Observable<Array<CalendarEvent<{ event: Event }>>>;

constructor(private http: Http) { }

ngOnInit(): void {
    this.fetchEvents();
}

fetchEvents(): void {

    this.events$ = this.http
        .get(this.apiUrl)
        .map((response) => response.json())
        .map(({ results }: { results: Event[] }) => {
            return results.map((event: Event) => {
                return {
                    title: event.title,
                    start: new Date(event.start),
                    end: new Date(event.end),
                    color: colors.yellow
                };
            });
        });

}

json data from api

[
{
"id": 2,
"user_id": 1,
"planning_id": 1,
"start": "2017-09-03T22:00:00.000Z",
"end": "2017-09-06T12:33:46.271Z",
"title": "A 3 day event",
"created_at": "2017-09-05 16:39:47",
"updated_at": "2017-09-05 16:39:47"
},
{
"id": 3,
"user_id": 1,
"planning_id": 1,
"start": "2017-09-03T22:00:00.000Z",
"end": "2017-09-06T12:33:46.271Z",
"title": "A 3 day event",
"created_at": "2017-09-07 13:27:36",
"updated_at": "2017-09-07 13:27:36"
}
]

Answer №1

Although it may be considered outdated, I have discovered a method to successfully integrate it with Angular 5

To declare the events, use the following syntax:

asyncEvents$: Observable<CalendarEvent[]>;

Subsequently, load your data using HttpClient

It should be noted that the API returns a DateEvent

loadEvents() {
    this.asyncEvents$ = this.http.get<DateEvent[]>(YOUR_URL) 
      .map(res => { 
        return res.map(event => { 
          return {
              title: event.label,
              start: new Date(event.startDate),
              color: {primary: event.color, secondary: "#D1E8FF"},
              meta: {
                event
              },
              allDay: true
            };
        });
      });
  }

Upon implementation, the functionality aligns with expectations

Answer №2

  • Run ng update
  • Execute ng update @angular/cli
  • Update using the command ng update @angular/core

Answer №3

Ensure to bring in the map operator:

import 'rxjs/add/operator/map';

Answer №4

To fix the problem, delete the node_module folder and then execute the command npm install. This resolved the issue for me.

Answer №5

For me, the issue arose when I needed to update my typescript version from

<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a9cdc0c9dccacbc0cbc9edef8bcbc0c9">[email protected]</a>
to
<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="87f1fcf5e0e6e7fcf7f1d5b1c7f7fc">[email protected]</a>
.

The error occurred after I upgraded my angular application from angular@10 to angular@11.

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

Cleaning up HTML strings in Angular may strip off attribute formatting

I've been experimenting and creating a function to dynamically generate form fields. Initially, the Angular sanitizer was removing <input> tags, so I discovered a way to work around this by bypassing the sanitation process for the HTML code stri ...

What is the most effective method for integrating templates using AngularJS and Webpack2?

UPDATE: I haven't come across a method to import templates using an import statement rather than require, but I have realized that I can streamline my configuration. In the webpack config, opt for html-loader over ngtemplate-loader for /\.html$/ ...

Styling Descendants Conditionally in Angular 2

.parent { color: blue; } .parent * { color: red; } .child { color: black; } .grandchild { color: green; } <div class="parent"> Parent <div>Child <div>GrandChild</div> </div> </div> Imagine a scenari ...

Host a web client on 'localhost' through https with npm

Resolved: I found a simple solution to my problem. Initially, I added the '--https' flag in webpack but encountered an issue with a hardcoded localhost:3003 in the template from themeforest. After locating and modifying the relevant line in webpa ...

When working with data in Angular, make sure to use any[] instead of any in app.component.html and app.component.ts to avoid causing overload errors

I'm new to working with Angular, specifically using Angular 15. I have a Rest API response that I need to parse and display in the UI using Angular. To achieve this, I employed the use of HttpClient for making GET requests and parsing the responses. ...

Guidance on Implementing Promises in Ionic 2 and Angular 2

Here are two functions that I need to implement: this.fetchQuizStorage(); this.retrieveQuizData(); fetchQuizStorage() { this.quizStorage.getAnswers().then(data => { return data; }); } retrieveQuizData() { this.quizData.getQuiz().t ...

Can TypeScript types be created using multiple comma-separated strings?

Is it feasible to define a custom type in TypeScript like Type LayoutType = "Left" | "Right" | "Top" | "Bottom" | "VCenter", that would combine values such as "Left,VCenter"? Or do I need to create a string literal for every possible combination? ...

Encountered numerous issues while attempting to execute the npm install -g angular-cli command

I encountered several errors while attempting to run the command npm install -g angular-cli on my Windows 10 64-bit system. Here's a look at the log: npm ERR! git clone --template=C:\Users\ben\AppData\Roaming\npm-cache\_ ...

Angular: Elf facade base class implementation for utilizing store mechanics

What is the most effective way to access the store within a facade base class, allowing for the encapsulation of commonly used methods for interacting with the store? Imagine we have a store (repository) export class SomeRepository { private readonly s ...

Update all occurrences of a particular value to null within the Realtime Database using Firebase Cloud Functions

I need to update the values of a specific userID linked to multiple post keys in my database by setting the userID to null. The userIDs are associated with post keys located in the path: posts/ivies/userIDs in my database. Take a look at how the database i ...

Warning: Google Map API alert for outdated Marker Class

Working on an application using the Google Maps TypeScript API, I came across a warning message when launching the app -> As of February 21, 2024, google.maps.Marker will no longer be available. Instead, developers are advised to use google.maps.marke ...

Issue: Unable to inject a service into a subscriber in NestJS

Currently, I am working on setting up a subscriber in NestJS to listen for create, update or delete events using TypeORM. When any of these events occur, my goal is to utilize an injected service to generate a new revision entry. However, I have encounter ...

Setting attributes within an object by looping through its keys

I define an enum called REPORT_PARAMETERS: enum REPORT_PARAMETERS { DEFECT_CODE = 'DEFECT_CODE', ORGANIZATION = 'ORGANIZATION' } In addition, I have a Form interface and two objects - form and formMappers that utilize the REPOR ...

Is it necessary to create a unit test for a basic operation involving RxJS?

Imagine a straightforward class that triggers a new event to an RxJS subject whenever the window is resized. Disregard any perceived complexities, as the main point is that this class generates an event. export class ResizeService { priv ...

Issues with Vite's global import feature not functioning properly in a production build

My current setup involves loading all markdown files within a directory using a glob import. The code snippet below depicts this functionality: const useGetChangelogs = () => { const [changelogs, setChangelogs] = useState<string[]>([]); useEf ...

Component not appearing in Storybook during rendering

I'm trying to incorporate the MUI Button Component into my storybook and then dynamically change MUI attributes like variant, color, and disabled status directly from the storybook. While I was successful in doing this with a simple plain HTML button, ...

I am experiencing an issue with React Select where it does not seem to recognize the value I have

Forgive me if this question sounds naive, I am still relatively new to Reactjs, I kindly ask not to suggest using Hooks as they are not compatible with my current project. Currently, I am focusing on a form and its validation process. Here is the snippe ...

The 'checked' property cannot be bound to 'mat-button-toggle' as it is not recognized as a valid property in Angular 9

I am encountering an issue with my Angular 9 application. I have integrated angular-material and imported the MatCheckboxModule correctly in the module. Here is the version of the material package I am using: "@angular/material": "^10.2.0&q ...

How to efficiently retrieve automatically generated elements by ID in Angular 2

In order to create a 6x6 grid, I am using the following code: <ion-grid> <ion-row *ngFor="let rowIndex of createRange(6)" [attr.id]="'row-'+rowIndex"> <ion-col col-2 *ngFor="let colIndex of createRange(6)" [attr.id]= ...

How can the count of specific values matching total records be determined in Angular/TypeScript using JSON?

In the dataset provided below, how can we determine the count of applicable impacts, non-applicable impacts, and FYI impacts for nested records under the assigned_to key instead of the parent record? The expected results should be: For 1st Record Appl ...