REST リソースと AngluarJS カレンダー コントロールの間のバインディングを実装できません。すべてのコンポーネントが個別に存在する限り機能しているため、何かが足りないか、論理的に理解できないようです。カレンダーの実装例として、この Plunker を使用しました: http://plnkr.co/edit/VbYDNK?p=preview
ビュー内:
...
<div ng-controller="CalendarCtrl" dev-calendar="uiConfig.calendar" class="span8 calendar" ng-model="eventSources" style="padding-top: 30px;"></div>
...
コントローラーの内部:
xyz.controller('MainController', function($scope, $location, $rootScope, MainModel) {
...
// REST call - getPendingObjectsByUser
$scope.pendingobjects = MainModel.pendingObjectsByUser.get(
{userId : $rootScope.currentUser.userId},
function(response) {
// do something
}, function(response) {
if(response.status == 404) {
$location.path('/notFound');
} else if (response.status == 500) {
$location.path('/error');
}
});
// this 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'
}
};
}
// this also works fine
今、私は次のような単純なバインディングをしようとしています:
$scope.events = [{title: $scope.pendingobjects.objectsData[0].title , type:'birthday', start: new Date(y, m, 1)}]
しかし、非同期動作のため、その「未定義」です。$scope.events 全体を使用可能な応答関数に入れると (以下に示すように)、カレンダーが機能しなくなります。
// getPendingObjectsByUser
$scope.pendingobjects = MainModel.pendingObjectsByUser.get(
{userId : $rootScope.currentUser.userId},
function(response) {
// do something
$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');
}
})
約束を守る必要がありますか、それとも自分の間違いを見て混乱するだけですか?