search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

$scope.scheduler is undefined

Asked by Anonymous
9 years ago.

Hello,

I am making this tutorial: http://code.daypilot.org/38221/angularjs-scheduler-tutorial

I can display the scheduler and load the resources from an external server that returns json values by other way I can't load events to the scheduler, the $scope.scheduler variable appears to be undefined when I debug it using Chrome dev. console. Here is some of my code:

Ctrl.js

$timeout(function() {
loadResources();
loadEvents($scope.scheduler.visibleStart(), $scope.scheduler.visibleEnd()); // here it says scheduler is undefined
});

View.html

<div ng-app="MyApp" ng-controller="Ctrl" >
<daypilot

  • scheduler id="scheduler" daypilot-config="schedulerConfig" daypilot-events="events" ></daypilot-scheduler>
  • </div>

Let me know what could be my error, maybe the scheduler view is not complete before my script is executed, it's driving me crazy.

Comment posted by Dan Letecky [DayPilot]
9 years ago.

The $timeout() wrapper should ensure that the scheduler is initialized before the loadResources() and loadEvents() methods are called. At that point, the object should be already stored in $scope.scheduler.

Can you try this minimum working example:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.1/angular.min.js"></script>
    <script src="https://javascript.daypilot.org/demo/js/daypilot-all.min.js"></script>
    <title>AngularJS Scheduler</title>
</head>
<body>

<div ng-app="main" ng-controller="DemoCtrl" >
    <daypilot-scheduler id="scheduler" daypilot-config="schedulerConfig" ></daypilot-scheduler>
</div>

<script>
    var app = angular.module('main', ['daypilot']).controller('DemoCtrl', function($scope, $timeout, $http) {
        $scope.schedulerConfig = {
            scale: "Day"
        };

        $timeout(function() {
            console.log($scope.scheduler);
        });
    });
</script>
</body>
</html>
Comment posted by Anonymous
9 years ago.

That works perfectly, it displays $scope.scheduler in Chrome console log.

Answer posted by Dan Letecky [DayPilot]
9 years ago.

Then you should be able to start with this code and extend it step-by-step until you have all you need or until it stops working.

If it stops working please check the last thing you added.

This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.