Array repeats simultaneously in json

1

I am trying to make a calendar where I will get the information in a rest request in angularjs. What I want to create is a calendar where you can register your events. With the json date attribute it inserts this event and registers an icon on that day.

My error is as you can see in the image it will fetch an array and insert it into the fields all and not only on the day it was registered in json. My function repeats 42 times which is the number of squares in the calendar. Anyone know where the error in my approach is I'm not realizing.

Image

Json

{"data":[
    {"title":"John", 
     "start":"2016-10-22"
    }, {
     "title":"João", 
     "start":"2016-10-25"
    }
]}

controller

$scope.setDayContent = function(date) {

    return $http ({
        method : "GET",
        url : "app/components/home/controller/test_calendar.json"
      }).then(function mySucces(response) {
            console.log(response.data.data[1]);
        }, function myError(response) {
          $scope.valor = response.statusText;
      }); 

html

    <calendar-md flex layout layout-fill
          calendar-direction="direction"
          on-prev-month="prevMonth"
          on-next-month="nextMonth"
          on-day-click="dayClick"
          ng-model='selectedDate'
          week-starts-on="firstDayOfWeek"
          tooltips="tooltips"
          day-format="dayFormat"
          day-content="setDayContent"
          ></calendar-md> 

version 2:

 $scope.loadData = function(){

      return $http ({
        method : "GET",
        url : "app/components/home/controller/test_calendar.json"
      }).then(function mySucces(response) {
           $scope.jsonData = response.data.data;
        }, function myError(response) {
          $scope.valor = response.statusText;
      }); 
    }


    $scope.setDayContent = function(date, content) {


//check if $scope.jsonData contains date parameter
// return title

    }; 
    
asked by anonymous 28.10.2016 / 17:20

1 answer

0

I have already understood the point that is generating this search loop.

Your setDayContent is called by the component so you can inform the content of the day, however you are not handling the parameters passed by the component and searching for the day it requested, but returning the whole calendar.

Suggestion: Treat your setDayContent to search in the request only the day he requested, which is in the parameters that the component sends you.

Or, loading the events before loading the component and on your setDayContent you look in that array or event object already loaded by the date it requested via parameter.

And you'd better go back there on the component page you're using and read its documentation better.

UPDATE

So, man, I took a look at documentation .

That's right, your mistake is not filtering the date that the component requested. The component gives you the option to respond with html, or with a promise.

    
28.10.2016 / 17:51