Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Events can't be added from api call #26

Open
ta4kazzz opened this issue Nov 25, 2015 · 8 comments
Open

Events can't be added from api call #26

ta4kazzz opened this issue Nov 25, 2015 · 8 comments

Comments

@ta4kazzz
Copy link

If the $scope.events object is created later on, you can't add it to the calendar witch is already initialized

@ta4kazzz
Copy link
Author

Never mind it takes a second for the watch to work on events. After that works perfectly, thanks for this calendar.

@sansan88
Copy link

do you have a solution how to add events later manually?

@arturmoreira
Copy link

@ta4kazzz, sorry to bother you, but can you explain how you managed to add events after the $scope.events is created?

@arturmoreira
Copy link

@ta4kazzz, I don't know if I've done it the better way (I'm not very experienced in AngularJS), but I think I solved it.
@sansan88, the solution I implemented was "inspired" on what @ta4kazzz said about "the watch to work on events". :-) Something like:

$scope.$watch('events', function() {
    console.log('events has changed');
});

@sansan88
Copy link

sansan88 commented Dec 8, 2015

@arturmoreira @ta4kazzz
sorry guys, but I was not able to manually add events after initial events where added. I'm doing something like this:
$scope.$watch('events', function() {
console.log('events has changed'); //gets fired 1 time. not on addTraining function..
});

$scope.addTraining = function() {
  $scope.events.push({
    titel: 'DI H2',
    beschreibung: "Training",
    date: "2015-11-24"
  });
};

@ta4kazzz
Copy link
Author

ta4kazzz commented Dec 9, 2015

$scope.events=[];

Do an api call here and initialize a temporary array first tempList.push({
titel: 'DI H2',
beschreibung: "Training",
date: "2015-11-24"
});
Then set it to events in the .then() of the api call
You should be able to do $scope.events = tempList;

This should work because the watch doesn't work if you do push to scope.events directly but worked for me on a full list assignment (don't know why) .

@sansan88
Copy link

I have found the problem in the source code and provided a pull request #27

@arturmoreira
Copy link

@sansan88, excellent work!!!

You see, as I said earlier, I'm not very experienced in AngularJS, so I wasn't even aware that a $watchCollection function was available... :-( That's why I ended up solving the problem as I wrote and as @ta4kazzz further detailed later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants