Angular 日历 ui,从数据库加载事件

Angular calendar ui, load events from database

我最近开始Angular js,为了一个项目,我必须使用日历-ui来管理数据库中的事件。

我设法正确使用日历,使用手动创建的第一个事件。我现在尝试绑定数据库中的数据,但现在问题来了。

这是我的代码:

$scope.eventsTab = [];
$scope.events = {};    
$http({
        url: "myurl",
        method: "POST",
        data: postData,
        headers: {'Content-Type': 'application/x-www-form-urlencoded'}
    }).success(function (data) {
            $scope.eventsTab.push({type:'session',title: data.title,start: new Date(y, m, 11, 15, 0),end: new Date(y, m, 20, 17, 30),url: 'http://google.com/'});
            $scope.events = {
                    color: 'orange',
                    textColor: 'white',
                    events: $scope.eventsTab
            };
    });
$scope.eventSources = [$scope.events];

这不起作用,我的日历中没有加载该事件。我认为这是由于异步问题引起的问题,因为如果我将来自 "success" 函数的代码放在下面的行

之前
$scope.eventSources = [$scope.events];   

,活动出现在日历中。

最后一件事,当我使用调试时,我正确地看到了数据库中的数据。

你能帮帮我吗?

谢谢!

编辑 1

如果我这样写代码

$http({
    url: "myurl",
    method: "POST",
    data: postData,
    headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).success(function (data) {
        $scope.eventsTab.push({type:'session',title: data.title,start: new Date(y, m, 11, 15, 0),end: new Date(y, m, 20, 17, 30),url: 'http://google.com/'});
        $scope.events = {
                color: 'orange',
                textColor: 'white',
                events: $scope.eventsTab
        };
        $scope.eventSources = [$scope.events];
});

我收到错误 TypeError: Cannot read 属性 'length' of undefined

并使用以下代码

$http({
    url: "myurl",
    method: "POST",
    data: postData,
    headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).success(function (data) {
        $scope.eventsTab.push({type:'session',title: data.title,start: new Date(y, m, 11, 15, 0),end: new Date(y, m, 20, 17, 30),url: 'http://google.com/'});
        $scope.events = {
                color: 'orange',
                textColor: 'white',
                events: $scope.eventsTab
        };
        $scope.eventSources = [$scope.events];
});
$scope.eventSources = [$scope.events];

没有错误,但同样的问题:事件未显示在日历中。

好的,一位朋友设法用其他方式做到了:

$scope.events = {
                url : "./webservices/getAllEvents",
                type : 'POST',
                data: {  
                   id: objectId,
                }   
};  

成功了,感谢 Gabin :)