2014-06-12 25 views
5

im sử dụng angular-ui-calendar trong trang web của tôi. Trong bộ điều khiển, tôi đã lớn không lành mạnh này:AngularJS + Fullcalendar gửi lỗi TypeError: Không thể đọc thuộc tính '__id' của undefined

define(['underscore'], function (_) { 
    "use strict"; 

    var SearchController = function ($scope, $location, OrdersService, UsersService) { 

     /* config object */ 
     $scope.uiConfig = { 
      calendar: { 
       height: 450, 
       editable: true, 
       firstDay: 0, 
       monthNames: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'], 
       monthNamesShort: ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic'], 
       dayNames: ['Domingo', 'Lunes', 'Martes', 'Miercoles', 'Jueves', 'Viernes', 'Sabado'], 
       dayNamesShort: ['Dom', 'Lun', 'Mar', 'Mie', 'Jue', 'Vie', 'Sab'], 
       header: { 
        left: '', 
        center: 'title', 
        right: '' 
       } 
      } 
     }; 
     $scope.eventSources = [$scope.events]; 

     var getTecnicians = function() { 
      UsersService.getTechs().then(function (techs) { 
       $scope.technicians = techs; 
      }); 
     }; 

     var search = function() { 
      var searchObject = $scope.$$childHead.searchForm; 
      UsersService.getCurrentStatus(searchObject.technician._id, searchObject.selectedStartDate).then(function (result) { 
       $scope.states = result[0].states; 
       for (var i = 0; i < $scope.states.length; i++) { 
        var event = {}; 
        if (i === $scope.states.length - 1) { 
         event = { 
          title: $scope.states[i].status, 
          start: $scope.states[i].date, 
          allday: true 
         }; 
        } else { 
         event = { 
          title: $scope.states[i].status, 
          start: $scope.states[i].date, 
          end: $scope.states[i + 1].date 
         }; 
        } 
        $scope.events.push(event) 
       } 
       if (result) { 
        $scope.haveData = true; 
       } 
      }); 
     }; 

     var init = function() { 
      $scope.search = search; 
      $scope.getTecnicians = getTecnicians(); 
      $scope.haveData = false; 
      $scope.events = []; 
     }; 
     init(); 
    }; 

    SearchController.$inject = ["$scope", "$location", "OrdersService", "UsersService"]; 

    return SearchController; 
}); 

Khi tôi bấm vào một nút i làm một yêu cầu get và lấy dữ liệu từ máy chủ, xử lý nó và tạo ra các sự kiện objets và đặt trong phạm vi của tôi.

Khi tôi hoàn thành nó, lịch chỉ cho tôi lỗi này:

ypeError: Cannot read property '__id' of undefined 
    at sourcesFingerprint (http://localhost:8000/bower_components/angular-ui-calendar/src/calendar.js:48:24) 
    at Object.changeWatcher.getTokens (http://localhost:8000/bower_components/angular-ui-calendar/src/calendar.js:88:21) 
    at Scope.$get.Scope.$digest (http://localhost:8000/bower_components/angular/angular.js:12243:40) 
    at Scope.$get.Scope.$apply (http://localhost:8000/bower_components/angular/angular.js:12516:24) 
    at done (http://localhost:8000/bower_components/angular/angular.js:8204:45) 
    at completeRequest (http://localhost:8000/bower_components/angular/angular.js:8412:7) 
    at XMLHttpRequest.xhr.onreadystatechange (http://localhost:8000/bower_components/angular/angular.js:8351:11) 

Cần i đặt một _id vào các sự kiện ..?

+0

bất kỳ bản cập nhật? Tôi nhận được lỗi tương tự –

+0

bản sao có thể có của [angularjs add value Không thể đặt thuộc tính 'id' của undefined] (http://stackoverflow.com/questions/24699081/angularjs-add-value-cannot-set-property-id -of-undefined) –

Trả lời

5

Tôi đã cùng một lỗi, một cách để sửa chữa nó là, initiliaze mảng sự kiện $ scope.events = [] và sau đó thực hiện yêu cầu http

0

Sử dụng tài liệu tham khảo này:

searchObject.technician.__id 

mà không xác định searchObject.technician là vấn đề.

0

Đây là lỗi từ lịch ui (here). Bạn đã thêm thuộc tính ng-model cho ui-calendar chưa?

<div ui-calendar ng-model="eventSources"></div> 

Ngoài ra, sau khi init(), Nó có vẻ là $scope.events là một mảng trống. Vì vậy, tôi nghĩ rằng bạn có thể vượt qua nó trực tiếp.

$scope.eventSources = $scope.events; // this is an array. 
0

Tôi chạy vào cùng một vấn đề. Nó đi xuống theo thứ tự mà bạn định nghĩa mọi thứ. Để an toàn, bạn nên khai báo các nguồn sự kiện của mình sau cùng.

Html:

<div ui-calendar ng-model="eventSources"></div> 

Bộ điều khiển:

$scope.events = [ 
    {title: 'Long Event',start: new Date()} 
]; 
$scope.eventSources = [$scope.events]; 
Các vấn đề liên quan