Are the events objects failing to render or is the scope not being broadcasted properly

I'm having trouble displaying my events using the ionic-calendar plugin by calling the $scope.loadEvents method. Unfortunately, the events are not showing up on the calendar.

Here is the link to the plugin I am using: https://github.com/twinssbc/Ionic-Calendar

I suspect that the issue lies in either my events not being properly returned within the getEvent() function or potentially because I'm incorrectly placing the

$scope.$broadcast('eventSourceChanged',$scope.eventSource);
as per the plugin's documentation.

Below is the code snippet from my controller file:

    $scope.loadEvents = function () {
        $scope.calendar.eventSource = getEvents();
        $scope.$broadcast('eventSourceChanged',$scope.eventSource);

    };

    function getEvents(object){

      var deferred = $q.defer();

        TimeSlotsModel.all()
            .then(function (result) {
                vm.data = result.data.data;

                var events = [];

                 angular.forEach(vm.data, function(value,key) {

                    var eventName = value.name;
                    var startDate = new Date(value.startDate);
                    var endDate = new Date(value.endDate);

                    var selectedStartingTime =new Date(value.startTime * 1000 );
                    var selectedEndingTime = new Date(value.endTime * 1000);

                    //timing is not right, needs fixing
                    startTime = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate(),selectedStartingTime.getHours(), selectedStartingTime.getUTCMinutes());
                    endTime = new Date(endDate.getFullYear(), endDate.getMonth(), endDate.getDate(),selectedEndingTime.getUTCHours(), selectedEndingTime.getUTCMinutes());                     
                    // console.log(startTime);
                    events.push({
                        title: 'Event -' + eventName,
                        startTime: startTime,
                        endTime: endTime,
                        allDay: false

                    });
            // console.log(eventName);
            console.log(events);
            // console.log(value);
            // console.log(key);
            // console.log(value);

             //value is the object!!
            })

            deferred.resolve(events);



            })
            return deferred.promise;

         }

Answer №1

The problem was successfully solved by directly assigning the events array to $scope.calendar.eventSource as shown below:

    function captureData(object){

    TimeSlotsModel.all()
        .then(function (result) {
            vm.data = result.data.data;

            var eventsList = [];

             angular.forEach(vm.data, function(dataValue,dataKey) {

                var eventName = dataValue.name;
                var startDate = new Date(dataValue.startDate);
                var endDate = new Date(dataValue.endDate);

                var selectedStartingTime =new Date(dataValue.startTime * 1000 );
                var selectedEndingTime = new Date(dataValue.endTime * 1000);

                //time needs adjustment
                startTime = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate(),selectedStartingTime.getUTCHours(), selectedStartingTime.getUTCMinutes());
                endTime = new Date(endDate.getFullYear(), endDate.getMonth(), endDate.getDate(),selectedEndingTime.getUTCHours(), selectedEndingTime.getUTCMinutes());                     
                // console.log(startTime);
                eventsList.push({
                    title: 'Event -' + eventName,
                    startTime: startTime,
                    endTime: endTime,
                    allDay: false
                });

                $scope.calendar.eventSource= eventsList;



        console.log(eventsList);
        // console.log(dataValue);




         //dataValue is referring to the object!!
        })
         return eventsList;

        })

     }

It was discovered that the issue was not related to $scope.$broadcast in the provided documentation.

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

Applying a consistent script with varying inputs on the same HTML page

Is it possible to create a JavaScript code that can be used across different sections of an HTML document? The goal is for the script to fetch data such as title, runtime, and plot from a specific URL request and insert this information into the appropriat ...

Utilizing ReactJS: Expanding my knowledge of updating array object indexes dynamically when removing elements

Currently, I am in the process of creating a to-do list application to improve my skills in working with ReactJS. This is how my initial state looks like: const [listx, setlistx] = useState( [ {id: 0, flavor: 'strawberry', ...

Issue encountered when updating npm to version 5.4.2: Unable to locate modules in ./node_modules/react-router-dom

When attempting to update my npm version from 3.10.10 to 5.4.2 and migrate react from 15.3.0 to 16.0, I deleted the node_modules folder and re-ran npm install. However, upon trying to run my application again, I encountered the following error: ERROR in ./ ...

Can using the jQuery.clone method impact other functions?

Assuming $dom is a jQuery element, can the following line be safely removed if a is not utilized thereafter? var a = $dom.clone(true,true); When using $dom.clone(false,false), it appears that there are no side effects. I believe this method doesn't ...

Is there a way to refresh autocomplete/autofill after form submission with a custom JavaScript function?

I've developed a Vue application that includes a form. Once the user clicks on submit, an Ajax request is made using Axios through a JavaScript function. The data being sent is a custom JSON object that I have constructed by combining the information ...

The Electronjs application encountered an error while loading with the message "ReferenceError: require is not defined."

Having trouble with an electron application as I encounter an error when running npm start: $ npm start > <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="483c2d3b3c087966786678">[email protected]</a> start C:& ...

Showing the output variable from node.js on a canvas

Is it possible to display the output of my node.js program, which consists of a series of points (x,y), on canvas without a browser? I came across this module that could potentially help with displaying the points: (https://www.npmjs.com/package/canvas) ...

Pinterest-style Angular-UI-Router modal

I am currently working on an app that features a gallery showcasing similar functionalities to . In Pinterest, clicking on a pin displays the pin page above the existing gallery without any information about the background gallery shown in the URL. Users c ...

What is the preferred default value for a property awaiting assignment from a GET response: Undefined or Null?

Say I need to display information about a product, but first I must make a GET request to get the data and assign it to the product. I'm wondering, should the default value for product in the data() function be undefined or null, and is there a differ ...

Issues with the play() method in Javascript across Firefox, Safari, and IE 11 are causing functionality problems

I developed a basic video and audio player that smoothly fades out an introductory image and starts or stops playing an mp4 file upon click. Everything functions properly in Chrome, but unfortunately does not work in other major browsers. Despite checking ...

Using Javascript to create bold text within a string

I have noticed that many people are asking about this issue, but it seems like a clear and simple answer is hard to come by. Currently, I am working with Vue and trying to display text from an object in a component. My goal is to highlight the price port ...

Unlocking the power of $http convenience shortcuts in AngularJS

I have developed a custom function (credit to source) that wraps an AngularJS $http function in a way that switches between browser XHR and cordova-plugin-advanced-http based on the device platform. While the function works seamlessly with $http({method:& ...

The second angular $http call fails to reach its intended destination

I am in the process of setting up a flow similar to oauth, where I delay sending an actual request until some initial negotiation has been completed. The initial negotiation is successful, however, when I attempt to make the request for the desired resour ...

Can you clarify the dissimilarity between `knex().select("id").from("users")` and `knex("users").select("id")` in Knex?

I have successfully connected knex with mysql and am working on a login form linked to a mysql database. Currently, I am performing a login check and I'm curious if there is any distinction between the following two queries: knex().select("id").from( ...

Just starting out with Angular - facing issues with setting up in eclipse

I'm attempting to create a test Angular project in Eclipse by copying the three files from the Angular website https://docs.angularjs.org/api/ng/directive/ngController into my Eclipse project. I initially created it as a static web project and then co ...

How can I merge my two custom filters into a single, more efficient custom filter?

I have developed two custom filters that are quite similar. The only distinction between these filters is the array they utilize. Therefore, I am considering creating a single custom filter and passing an array as a parameter to it. The arrays I intend to ...

How can I retrieve a ref from a child component in Vue.js?

As a beginner to vuejs with limited JavaScript experience, I am using Vue3 in Laravel. I have a child component that exposes a ref on an input field like so: <input v-model="raw_input" ref="raw" @input="checkLen ...

Obtain a collection of the corresponding keys for a given value from dictionaries

I'm implementing a function that retrieves a list of keys associated with a specific value in the dictionary. Although I am able to print out the first key successfully, I'm facing difficulties in displaying subsequent keys. I understand that I ...

What is the reason that PHP has the ability to set Cookies but Local Storage does not?

Let's take a step back to the era of cookies, not too far back since they are considered old but still quite relevant. PHP allows you to set and read them even though they are a client-side technology; however, JavaScript can also be used completely o ...

Setting the iDisplayLength property in jQuery Datatables to -1 will display all rows in the table

Using jQuery Datatables, I am trying to populate a table with entries from a server via ajax. The data retrieval works perfectly, and I am able to display them in the table. However, I am facing an issue where I want to show all rows/entries at once. I hav ...