Invoke the method in customButton component of fullcalendar

I've integrated a custom button into my fullcalendar:

ngOnInit() {
this.calendarOptions = {
  customButtons: {
    custom1: {
      text: 'Add event',
      click() {
        this.openModal();
     }
    }
  },
  height: 600,
  editable: true,
  eventLimit: false,
  locale: 'lt',
  header: {
    left: 'prev,next today, custom1,custom2',
    center: 'title',
    right: 'month,agendaWeek,agendaDay,listMonth'
  },
  events: ''
};}

When the button is clicked, I intend to execute the following function:

    openModal() {
console.log('opened');
// '<app-add-event></app-add-event>';}

However, an error occurs stating

zone.js:199 Uncaught TypeError: this.openModal is not a function
    at HTMLButtonElement.click (events-calendar.component.ts:20)

I'm unsure why this error is happening. How should I properly call a custom function?

I've also attempted:

 this.calendarOptions = {
  customButtons: {
    custom1: {
      text: 'Pridėti įvykį',
      click:
        this.openModal
    }
  }, ...   };

In this scenario, console.log(); does work, but I still encounter an error afterwards. What could be the issue here?

Do I need to declare this function somewhere else in the code?

<ng-fullcalendar #ucCalendar [options]="calendarOptions" (eventClick)="eventClick($event.detail)" (eventDrop)="updateEvent($event.detail)"
          (eventResize)="updateEvent($event.detail)" (clickButton)="clickButton($event.detail)"></ng-fullcalendar>

Answer №1

According to the fullcalendar documentation:

  customButtons: {
    myCustomButton: {
      text: 'custom!',
      click: function() {
        alert('clicked the custom button!');
      }
    }
  }

Your custom button declaration seems to have an issue with the click() property.

I see that you are still encountering errors related to this.openModal. Instead of using click: this.openModal, you might want to try using

click : () => console.log('clicked')
. If it works, the problem could be due to how you are using this.

Answer №2

To implement a fat arrow function, follow these steps:

this.calendarOptions = {
  customButtons: {
    custom1: {
      text: 'Create event',
      click: () => this.openModalPopup()
    }
  }
}

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

Leveraging the power of angular's $asyncValidators by implementing a cache

I've created a validation directive that verifies a value against an endpoint App.directive('validate', function(fooService, $q) { return { restrict: "A", require: "ngModel", link: function(scope, elem, attrs, ngModel) { ...

Accessing a PHP variable within an AJAX handling script

Upon user login, the email is stored in $email (I also tried global $email). Subsequently, a form allows the user to input their roommate's name to search for existing appointments. Incorporating AJAX $("#reserveAPickupAppointmentForm3").submit (fun ...

Switch color in Material-UI based on props

Utilizing code inspired by the Material-UI documentation on customizing the switch, you can customize the switch color to be blue: import React from 'react' import Switch from '@material-ui/core/Switch' import {withStyles} from '@ ...

Is it possible to capture a Browser TAB click event using JavaScript or AngularJS?

How can I trigger an event when returning to a tab? For instance: Let's say I have opened four tabs in the same browser with the same URL: such as: http://127.0.0.1:/blabla http://127.0.0.1:/blabla http://127.0.0.1:/blabla http://127.0.0.1:/blabla ...

Implementing Asynchronous Rendering in React Router 4

I've been working with React Router 4 and trying to implement Redirect(Auth) following a guide. However, I'm facing an issue with rendering based on the promise returned by an AJAX call. It seems like my rendering logic inside the promise is not ...

Enable strict mode for older web browsers

I would like to incorporate the "use strict"; statement into my function, but unfortunately it is not compatible with older browsers such as ie7 and ie8. Is there a workaround to ensure this functionality works in legacy browsers? Could someone please cla ...

Overriding the w-4xl with sm:text-2xl in Tailwind CSS

Struggling to achieve responsive design on my Pages, especially with changing text size when the screen is small. I've been following all the correct steps and maintaining the right order. However, whenever I set 'sm', it seems to override a ...

Can the child component ensure that the Context value is not null?

In the process of developing a Next.js/React application with TypeScript, I've implemented a UserContext in pages/_app.js that supplies a user: User | null object to all child components. Additionally, there's a ProtectedRoute component designed ...

Display the number of items that have been filtered as soon as the Mixitup page loads

Currently, I am utilizing MixItUp 3 for sorting and filtering items, with the goal of displaying the count of items within each filter category upon the initial page load. Despite attempting a solution found on SO (mixitup counting visible items on initial ...

What could be causing the issue with my custom AlloyEditor UI extension?

After following the instructions in this guide to integrate alloyeditor as a WYSIWYG editor into Contentful, I successfully added the extension to my contentful staging space. However, despite copying the html page from the github repository and includin ...

Utilize Vue.js and express.js to distribute HTML files securely

Currently, my tech stack includes Vue.js for the frontend and Express.js for the backend. When I kick off the express.js server using npm start, my goal is to serve the Vue frontend component. By utilizing the Vue generator and Express generator, I attemp ...

Nested loop with Angular and Bootstrap Modal

I am trying to implement a Modal in Angular to display the details of a row in a table with matching IDs, but I'm encountering an issue where only the data from the first row is shown when I open the Modal. The other rows do not seem to work correctly ...

issue arising from integrating material-ui components with code in a react javascript application

Struggling with integrating code and material-ui components in react jsx, I encountered an issue. Here's the problematic snippet: const icols = 0; const makeTableRow = ( x, i, formColumns, handleRemove, handleSelect) => <TableRow key ...

Angular - Jest can manage the importing of the main entry point

Currently, I am attempting to create a simple test for a component that utilizes rete.js. However, the test is failing due to difficulty handling one of the required import paths. Component import { Component, ElementRef, Injector, ViewChild } from ' ...

Implement the Vue.js @click directive in a location outside of an HTML element

I've set up a link like this: <a href="#" @click="modal=true">Open modal</a> Here's the data setup: export default { data () { return { modal: false } } } Is there a way to trigger the cli ...

Ways to Manage modals responses as services in AngularJS

I am a beginner in the world of JavaScript and AngularJS. I am fascinated by some of the concepts within JS, like trying to create a modal service using the example I found online. I am eager to delve deeper into what exactly is happening under the hood, e ...

JavaScript Website Struggling to Make Postman REST API Call to Parse Server

I have set up a Parse API Server on Azure and can successfully make REST API calls to it using Postman. However, when I try to replicate this process in my web app using the jQuery AJAX code snippet generated by Postman, I encounter a 400 (bad request) err ...

Encountering a problem with the click handler when trying to log in with Google on

Currently, I am working on integrating social login with Google into my Angular project Below is the relevant HTML code for the login: <button (click)="prepareLoginButton()" #googleSignUp >Login Using Google</button> And here is the ...

Is Jquery struggling to modify the visual enhancements?

Check out this link, I need the sidebar design to be similar to what is shown in the provided link. Furthermore, I am looking for a way to have a pointer that follows along with my selection on different labels such as home, charts, etc. Can anyone assis ...

What strategies can I use to prevent making multiple API calls inside setInterval when initializing a new connection in a socket?

I am currently working on implementing a socket system where users can request a function with an ID, and after receiving the ID, I send requests to an API every second and emit the response back to the user. Issue: Every time a new user requests the same ...