Comments (8)
Hi Clemouuche,
the problem is not related to the component itself, but the scoping inside your clickday function.
in your fullCalendar class, try the following:
dayClick: this.clickday.bind(this),
OR
dayClick: (date, jsEvent, view) => this.clickDay(date, jsEvent, view),
then you should be able to output the event to your parent component
More info at:
http://stackoverflow.com/questions/20627138/typescript-this-scoping-issue-when-called-in-jquery-callback
Note that you don't need to check if valueChange is defined or not anymore, since you already initiated it on variable declaration
@Output() valueChange: EventEmitter<any> = new EventEmitter();
hope this helps
from ng2-fullcalendar.
hi Clemouuche, can you put the code of your component so I can better suggest the best practice?
from ng2-fullcalendar.
Just to know, I'm using ionic2
`import { Component, Input, Output, NgZone, EventEmitter } from '@angular/core';
import { NavController } from 'ionic-angular'
import {Observable} from 'rxjs/Rx';
import * as moment from 'moment';
import { DataService } from '../../providers/data-service';
import { Local } from '../../providers/local'
import { DispoAddPage } from '../../pages/dispo-add/dispo-add';
/*
Generated class for the FullCalendar component.
See https://angular.io/docs/ts/latest/api/core/index/ComponentMetadata-class.html
for more info on Angular 2 Components.
*/
@component({
selector: 'full-calendar',
templateUrl: 'full-calendar.html'
})
export class FullCalendarComponent {
@input('idCoach') idCoach: any;
@output('change') valueChange: EventEmitter = new EventEmitter();
eventOut: any;
events: any = []
calendarOptions:any = {};
constructor(
private cache: DataService,
private local: Local,
private zone: NgZone,
private nav: NavController
) {}
ngAfterViewInit() {
this.calendarOptions = {
height: 'parent',
contentHeight: 'auto',
local: 'fr',
fixedWeekCount : false,
defaultDate: moment().format('YYYY-MM-DD'),
editable: true,
eventLimit: false, // allow "more" link when too many events
defaultView: 'agendaWeek',
allDaySlot: false,
slotLabelFormat: 'HH:mm',
minTime: '06:00:00',
maxTime: '23:00:00',
header: {
left: '',
center: 'prev, title, next',
right: ''
},
events: [],
eventClick: function(event, jsEvent, view ) {
//console.log('coucou ;) '+moment(event.start).format('YYYY-MM DD HH:mm:ss'))
//this.eventOut = event
//this.eventOut.type = 'update'
},
dayClick: this.clickday,
};
this.getCoachDispo()
}
ngOnInit(): void {
}
getCoachDispo(): void {
this.local.get('userInfos').then((res) => {
this.idCoach = JSON.parse(res).id
var observable = this.cache.load('events', {
'filter[id_customer]': this.idCoach,
'filter[nb_days]': '30',
'filter[deleted]': '0',
'display': 'full'
})
observable.subscribe(
res => {
this.fetchDispo2(res.events)
//console.log(JSON.stringify(res))
},
err => {
//this.log.error('ca189ead3e783f3cc87ae611a7d001a1', 'GET /events coach page', err)
})
})
}
fetchDispo2(events): any {
var dispo = events
events.forEach(
(elem, i) => {
if (elem.deleted == 0) {
dispo[i].start = elem.start_date
dispo[i].end = elem.end_date
delete dispo[i].start_date
delete dispo[i].end_date
dispo[i].title = ""
}
if (elem.status == "available") {
dispo[i].color = '#00B888'
}
if (elem.status == "ok") {
dispo[i].color = '#e74c3c'
}
if (elem.status == "pending") {
dispo[i].color = '#f39c12'
}
}
)
this.zone.run(
() => {
this.calendarOptions.events = dispo
//console.log(JSON.stringify(this.calendarOptions.events, null, 2))
}
)
}
clickday(date, jsEvent, view): void {
console.log('hé '+JSON.stringify(date))
this.eventOut = {}
this.eventOut.type = 'new'
this.eventOut.date = date
//this.valueChange = new EventEmitter()
if (this.valueChange) {
console.log('defined')
this.valueChange.emit({
value: this.eventOut
})
}
else {
console.log('undefined')
this.valueChange = new EventEmitter()
this.valueChange.emit({
value: this.eventOut
})
}
console.log('eventOut : '+JSON.stringify(this.eventOut))
}
}
`
from ng2-fullcalendar.
Hi @nekken ,
good day!
I'm having a problem to show those event from database. When I hard coded those event it works but when I'm calling it from API it doesn't work.
here's my code
showEvent(){
this._event_service.getEventList()
.subscribe(
data => {
this.events = Array.from(data);
this.calendarOptions['events'] = this.events;
console.log(this.calendarOptions['events']);
let event = this.events.length;
for (var i = 0; i < event; i++) {
this.events[i].title;
console.log(this.events[i].title);
}
},
err => this.catchError(err)
);
}
ngOnInit() {
this.showEvent();
}
I hope you can help me with this one, I am very new in Angular 2
from ng2-fullcalendar.
@alyssa19 the response object from the server should have property id, title and start, then only it will bind properly and then you can have other properties inthe object but those 3 are must.
from ng2-fullcalendar.
@alyssa19 did you manage to get this to work? I'm having the same issue. Can't get it to display API data from an observable at all.
from ng2-fullcalendar.
@alyssa19 @woodm1 any news on this? Is it possible to display API data from an observable with fullcalendar at all or am I wasting time?
from ng2-fullcalendar.
If you're having problems getting it to display the data from an observable, have a look at akveo/ngx-admin#331
I got it to work & there's an example in there
from ng2-fullcalendar.
Related Issues (20)
- how to enable week ,day and month buttons that are in the header on the fullcalender ? HOT 2
- I can't install via npm
- Two calendar inside same view, show only one calendar HOT 1
- Smallfix for switch
- Angular 4 Styling Issue
- TimeZone Issue
- Moment Warning
- Angular4,found version 4, expected 3 HOT 6
- Angular 5 / CLI issue installing
- How to setup currant date HOT 1
- Issue with full calendar on event clicked in angular 4
- Angular 5 Support..?
- Installation with Angular 2 issues HOT 1
- full calendar resources unable to fetch HOT 1
- ''fullcalendar'' has no exported member 'Options' HOT 1
- Why can't I see the exact date of the week?
- compilation errors with angular 6 HOT 1
- Google Calendar integration problem
- How to trigger the Button event HOT 1
- How to disable previous and next buttons based on some condition in angular 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ng2-fullcalendar.