0

I'm trying to use AngularUI directive calendar and set its source in callback function in my own directive (so basically I wrap directive into directive).

So use of my directive in html is:

<calendar><calendar>

I have this template form my wrapping directive (calendar.html):

<div class="row-fluid" >
 <div data-ui-calendar="{height: 450,editable: false}" class="span8 calendar" data-ng-model="events"></div>
</div>

And declared this directive:

.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
         }
     };

So the problem is I'm trying to set scope.events in the callback function but it doesn't show anything in browser (but the code in callback function is executed). If I try it outside the callback, it would work but I have to load data from server first... How to make it work? I would think that the trick with mainScope would work or even directly scope.events but nope. Thanks

It looks like some issue with AngularUI's fullcalendar. I tried to change the directive template to simple input box and changed value binded with ng-model in the callback function and it worked fine

2 Answers 2

1

I'm not a fan of answering own questions, but it took me a lot of nerves and solution is not quite "obvious". I used to have AngularUI v.0.3.0. So I updated to 0.3.2 and problem is gone :/

Sign up to request clarification or add additional context in comments.

Comments

0

Try doing

scope.$apply(function(){
  mainScope.events = data;
});

1 Comment

Unfortunately, that throws exception: Error: $digest already in progress at Error (<anonymous>) at beginPhase (app/lib/angular/angular.js:8067:15)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.