The issue with the angular-ui ui-calendar is that it does not reflect changes made to the Event Source Object or

I implemented fullcalendar.js into my angular app using angular-ui / ui-calendar.
(angularjs 1.3.10, fullcalendar 2.2.6, ui-calendar 0.9.0-beta.1, jQuery 2.1.3, moment 2.9.0 & angular-moment 0.9.0)

Within the calendar, I utilize the dayClick function as a datepicker to:
- assign the selected date to scope (for other application purposes)
- update the Event Source Object events array with the chosen date
- showcase the recently updated selected date (newly updated event) on the calendar

While I can successfully accomplish the first two tasks, the third one does not update automatically.

According to the documentation:

An Event Sources objects needs to be created to pass into ng-model.
This object's values will be watched for changes. If a change occurs, then that specific calendar will call the appropriate fullCalendar method.

However, it appears that the calendar is not updating automatically in this scenario...

Is this a flaw within ui-calendar or am I overlooking something?

Interestingly, when the calendar is inside an ng-if tab and I switch between tabs, the calendar updates correctly (after switching).

View this jsfiddle and observe:
- run, select a date (note the updated events array)
- toggle Tab 2 then back to Tab 1 - notice the correct display of the date now...

The HTML code snippet looks like:

<div ui-calendar="uiConfig.calendar" ng-model="calendarDate" calendar="myCalendar1"></div>

The controller code resembles:

myApp.controller('MainCtrl', function($scope, $filter, moment, uiCalendarConfig){

    $scope.calendarDate = [
        {
            events: [
                {
                    title: 'From',
                    start: '2015-01-31',
                    allDay: true,
                    rendering: 'background',
                    backgroundColor: '#f26522',
                },
            ],
        }
    ];

    $scope.setCalDate = function(date, jsEvent, view) {
            var dateFrom = moment(date).format('YYYY-MM-DD');                   
            $scope.calendarDate[0].events[0].start = dateFrom;              
            $scope.dateFrom = $filter('date')(dateFrom, 'yyyy-MM-dd');;         
    };

    $scope.uiConfig = {
        calendarFrom : {
            editable : false,
            aspectRatio: 2,
            header : {
                left : 'title',
                center : '',
                right : 'today prev,next'
            },
            dayClick : $scope.setCalDate,
            background: '#f26522',
        },
    };
});

PS took a glance at this question (similar issue), however, it was asked several versions ago - also, the suggested solution

calendar.fullCalendar('refetchEvents');
doesn't work due to the undefined calendar object - uncertain about what calendar.fullCalendar would entail in my code...

Answer №1

It appears there is an issue with ui-calendar that I have not managed to resolve yet. However, as a temporary solution, you can create a new event instead of updating the current one: simply replace

$scope.calendarDate[0].events[0].start = dateFrom;
with
$scope.calendarDate[0].events.push({title: 'From', start: selectedDate, allDay: true, rendering: 'background', backgroundColor: '#f26522'});
: http://jsfiddle.net/gidoca/kwsrnopz/.

Additionally, to access the calendar object for calling the fullCalendar function, you would use $scope.myCalendar1 - ui-calendar adds it to the scope using the name specified in the HTML's calendar attribute.

Answer №2

I encountered similar challenges, but was able to resolve them using two distinct methods.

If you're loading content dynamically through $http, utilize uiCalendarConfig addEventSource

uiCalendarConfig.calendars['mycalendar'].fullCalendar('addEventSource', $scope.events);

If the calendar visibility toggles between hidden and visible upon loading, make use of refetchEvents

$timeout(function(){
   uiCalendarConfig.calendars['mycalendar'].fullCalendar('refetchEvents');  
})

The $timeout function allows the calendar to compile within the scope properly

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

Stop and start an Express.js server using the original port number

Currently, my Node.js application utilizes Express.js to handle incoming connections. The code snippet looks something like this: const express = require("express"); var server = express(); server.get("/test", (req, res) => testResponse(req, res)); ser ...

Tips for incorporating several form input outputs into an array State in React

I am an aspiring coder diving into the world of React by working on a simple app that helps calculate how much money one has, designed for my kids to use and learn from. The app consists of 5 components, each with its own input field. These fields allow us ...

"JavaScript issue: receiving 'undefined' when trying to retrieve input

This code snippet is for a web app that tracks the number of losses in a game. The problem arises when trying to retrieve the value, which returns undefined. Every time I reference the username variable, it returns undefined. document.addEventListener(&a ...

Adjust the height of an element using CSS based on the height of another

Is there a way to have two divs per row, where the second div always displays its full content and the height of the first div matches the height of the second div? If the content in the first div exceeds the height, it should be scrollable. I've atte ...

The issue lies in AngularJS where updating data that is bound does not automatically update the corresponding template

Currently, I am in the process of building my very first mobile app using a combination of html5, cordova, angularjs, and jQuery. Initially, I had no issues creating my controller and template. The data that I bind to the template is retrieved from a .net ...

Displaying image alt text on hover using pure JavaScript

Is there a way to hover over images on my webpage and display their alt text using vanilla javascript, without relying on jQuery? Here is the code for my images: <a href="<?php echo $displayData['href']; ?>" class="group"> <d ...

Retrieve the route parameters and exhibit the default option in a dropdown menu using Angular 2/4/5, along with translations implemented through ngx-translate

Is there a way to extract route parameters from a URL and then display them in a drop-down menu? I've attempted some solutions using ActivatedRoute, but they are not returning the first value after the base reference. For instance, If the URL is: l ...

Showcase -solely one property object- from numerous property objects enclosed within an array

Hello, I am seeking assistance as I have recently begun learning about angularJS. I am working with objects that have keys such as: scope.eventList=[]; for(){ var event = { id : hash, ...

Problem encountered during JSON parsing in JavaScript causing loss of the "id" field

Upon parsing this string using JSON.parse(), I noticed that some objects contain id = null. However, upon inspection, I am unable to find any object with id = null. Is there a potential issue here? console.log("TERRITORIES000: "); ...

AngularJS dynamically style form fields on input focus

How can angularjs be used to format an input field value based on whether or not the input has focus? I need help with displaying numbers in an input field rounded to 2 decimal places, but switching to show the full value when the user clicks on the field ...

`Exploring AngularJS scopes with the Batarang Chrome extension`

I am curious about AngularJs scopes and how they can be examined using the Batarang Chrome extension. Here is the HTML I have: <!doctype html> <html lang="en" ng-app="myApp"> <head> <meta charset="utf-8"> <title>My A ...

Unable to populate a calendar with JSON events for the entire schedule

I have been experimenting with the following code for integrating fullcalendar:- <doctype! html> <html lang="urf-8"> <head> <title>Full calendar</title> <link rel="stylesheet" href="fullcalendar.css"/> ...

Is it possible to create Interactive Tabs using a Global BehaviorSubject?

Trying to adjust tab visibility based on different sections of the Ionic app, an approach involving a global boolean BehaviorSubject is being utilized. The encapsulated code has been condensed for brevity. In the provider/service globals.ts file, the foll ...

Tracking and monitoring the advancement of multiple ajax post requests

Currently, I am utilizing jQuery for multiple ajax POST requests. In order to effectively manage the success or failure of each request and track the overall progress of the entire batch, my goal is to update the UI with a progress bar and information on t ...

include in the subsequent function's .each operation

Below is the function that I am currently using: $(".formact").validate({ submitHandler: function (form) { $.ajax({ type: "POST", url: "act_cant.php", data: $(".formact").serialize(), beforeSend: function() { ...

Incorporating an HTTP header into d3.json using queue.js

I know that I can include a header in a D3 JSON request by using the following code: d3.json("http://localhost:8080/data") .header("Application-ID", "1") However, I'm uncertain about how to add this header when utilizing queue's defer method. ...

Improving User Experience with HTML Form Currency Field: Automatically Formatting Currency to 2 Decimal Places and Setting Maximum Length

Hello there, I am currently facing an issue with the currency auto-formatting in a deposit field on my form. The formatting adds 2 decimal places (for example, when a user types 2500, the field displays 25.00). However, the script I wrote does not seem to ...

Enhancing Real-time Communication with NodeJS and NowJs Servers

Recently, I stumbled upon NodeJS and NowJS and I'm fascinated by the technology. My goal is to develop a Facebook-style instant commenting application where users can post comments that will instantly appear on the feed. After watching the screencast ...

Issue with Jquery prevents clicking on hyperlinks

I have a table where table rows can be clicked. However, some cells cannot be clicked if they contain hyperlinks. This is because having both actions - one for clicking the table row and another for clicking the hyperlink - can cause confusion. Therefore, ...

Concerns have been raised regarding the lack of light and shadows being detected by THREE.BufferGeometry in JavaScript/th

I've been trying to generate terrain using noise functions, but I'm running into an issue where the BufferGeometry mesh isn't receiving any light from PointLight. When I switch to AmbientLight, the BufferGeometry is visible, but not with Poi ...