AngularUI ディレクティブ カレンダーを使用して、そのソースを自分のディレクティブのコールバック関数に設定しようとしています (したがって、基本的にディレクティブをディレクティブにラップします)。
したがって、htmlでの私のディレクティブの使用は次のとおりです。
<calendar><calendar>
このテンプレートは、ラッピング ディレクティブ (calendar.html) から作成されます。
<div class="row-fluid" >
<div data-ui-calendar="{height: 450,editable: false}" class="span8 calendar" data-ng-model="events"></div>
</div>
そして、このディレクティブを宣言しました:
.directive('calendar', ['calendarFct', function(calendarFct) {
return {
restrict: 'E',
templateUrl: 'partials/directives/calendar.html',
link: function(scope, element, attrs) {
var mainScope = scope;
// load data from server
calendarFct.getEvents(function(data) {
mainScope.events = data; // DOESN'T WORK
});
mainScope.events = data; // this would work, but I don't have "data" here
}
};
したがって、問題は、コールバック関数で scope.events を設定しようとしていますが、ブラウザーには何も表示されません (ただし、コールバック関数のコードは実行されます)。コールバックの外で試してみるとうまくいきますが、最初にサーバーからデータをロードする必要があります...どうすればうまくいきますか? mainScope
のトリックが機能するか、直接でも機能すると思いますがscope.events
、違います。ありがとう
AngularUI の fullcalendar に問題があるようです。ディレクティブ テンプレートを単純な入力ボックスに変更して、コールバック関数で ng-model にバインドされた値を変更しようとしたところ、問題なく動作しました