0

I'm trying to make a calendar where I will get the information in a request resto in AngularJS. What I want to create a calendar where you give to register your events. With the date of the json attribute it to enter this event and registers an icon that day.

My error is as you can see in the picture it will fetch an array and insert all the fields and not only on the day that was registered to json. My job is repeated 42 times which is the number of squares on the calendar. Does anyone know where is the error in my approach is that I do not understand.

Image

enter image description here

controller

$scope.setDayContent = function(date) {

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

}; 

json

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

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> 
2
  • Can you please tell me what is the output of the response.data.data ? Commented Oct 28, 2016 at 15:28
  • return response.data.data[0].title; = John return response.data.data = i see the 2 arrays Commented Oct 28, 2016 at 15:33

1 Answer 1

1

Your function setDateContent runs for each date in the calendar. In your success callback, you need to add logic to check the data that was returned and set a variable or return the information that is needed for that day.

You should not be loading the JSON for each day. YOu should load the JSON and then check it for each date in the function.

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

$scope.setDayContent = function(date) {

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

}; 
Sign up to request clarification or add additional context in comments.

3 Comments

when i call the $scope.jsonData in my setDayContent i have one error "ReferenceError: jsonData is not defined". Why? Because of different functions?
You need to call th $scope.loadData function in an init or when the controller loads.
the expression $watch dont resolve my problem? I'm still trying to work it out

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.