model view controller - How to bind AngularJS Calendar to a REST resource using MVP -
i’m failing implement binding between rest resource , angluarjs calendar control. seems i’m missing or don’t logically since components working long there separate. used plunker example of calendar implementation: http://plnkr.co/edit/vbydnk?p=preview
inside view:
... <div ng-controller="calendarctrl" dev-calendar="uiconfig.calendar" class="span8 calendar" ng-model="eventsources" style="padding-top: 30px;"></div> ...
inside controller:
xyz.controller('maincontroller', function($scope, $location, $rootscope, mainmodel) { ... // rest call - getpendingobjectsbyuser $scope.pendingobjects = mainmodel.pendingobjectsbyuser.get( {userid : $rootscope.currentuser.userid}, function(response) { // }, function(response) { if(response.status == 404) { $location.path('/notfound'); } else if (response.status == 500) { $location.path('/error'); } }); // works fine ... function calendarctrl($scope) { var date = new date();var d = date.getdate();var m = date.getmonth();var y = date.getfullyear(); $scope.events = [{type:'birthday', title: 'brian',start: new date(y, m, 1)}]; $scope.eventsources = [$scope.events]; $scope.uiconfig = { calendar:{ height: 450, editable: false, defaultview: 'month' } }; } // works fine
now i'm trying simple binding like:
$scope.events = [{title: $scope.pendingobjects.objectsdata[0].title , type:'birthday', start: new date(y, m, 1)}]
but due asynchronous behavior “undefined”. if put whole $scope.events response function available (like shown below), calendar doesn’t work anymore.
// getpendingobjectsbyuser $scope.pendingobjects = mainmodel.pendingobjectsbyuser.get( {userid : $rootscope.currentuser.userid}, function(response) { // $scope.events = [{type:'birthday', title:'$scope.pendingobjects.objectsdata[0].title',start: new date(y, m, 1)}] }, function(response) { if(response.status == 404) { $location.path('/notfound'); } else if (response.status == 500) { $location.path('/error'); } })
do need work promises or confused see mistake?
why not bind events resource straight away? so:
$scope.events = function (start, end, callback) { var events = mainmodel.pendingobjectsbyuser.get({ userid : $rootscope.currentuser.userid }); // promise events.$promise.then(function (val) { $scope.events = events; callback($scope.events); } ); }; $scope.eventsources = [$scope.events];