1
I am trying to make a calendar where I will get the information in a request Rest in Angularjs. What I want to create a calendar where you can record your events. With the json date attribute he enters that event and registers an icon on that day.
My mistake is as you can see in the image it will fetch an array and insert it into all fields and not just the day it was registered in json. My function repeats 42 times the number of the squares in the calendar. Does anyone know where the error in my approach is that I don’t understand.
Imagery
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
};
Your problem seems to me that every day you are calling an ajax request. If you see on the console you probably have 42 ajax calls, as opposed to just one. I’m not familiar with the angular API to help, but if no one answers, I’ll take a look at the weekend.
+1
– Sergio
I need to create a logical attribute so that he realizes that that specific date can only show 1 time and not 42 times. I think this is it, correct me if I’m wrong
– Jose Cerejo