angularjs - How do I use jsonp with angular-ui calendar -
I am using the angular-u calendar to try and drag events from my API. The API is on a different domain so I have to use jsonp.
I have tried many ways to get this work, but events on my calendar can not be found.
I create a service to call API
angular.module ('myapp.services', ['ngResource']) .factory ('SurgerySource', ['$ Resource', ceremony ($ resource) {return $ resource ('http://api.mydomain.com/calendar.json?callback=JSON_CALLBACK&start=:start&end=seend', {start: ' @start ', end' @ end '}, {Jsonp_query: {method:' JSONP ', isArray: true}});}]);
In the controller for my calendar, I can call it directly and get the event on the calendar
angular.module ('myapp.schedule ', [' Ui.calendar ',' ui.bootstrap ',' myapp.services']) .controller ('ScheduleCtrl', function ScheduleCtrl ($ scope, SurgerySource) {$ scope.surgeries = SurgerySource.jsonp_query ({start: + 13 9 6162800, end: 1399791600}); $ scope.uiConfig = {...}; $ scope.eventSources = [$ scope.surgeries];});
This populates the calendar with a hardcode date range. Although I could not understand the way to start using Calendar View and get a way to the end, so I tried to use an event source which calls the function (according to the document here) from this view to the date range Gets, but I can not get back Jason back into the $ realm
$ scope.eventSource = function (start, end, callback) {s = new date (start) .getTime () / 1000; E = new date (end) .getTime () / 1000; Var Event Processed = SurgerySource Jasonp_query ({start: s, end: e}); Call event (eventPromise); };
If I analyze the phenomenon, then I think it is $$ with a $ object object and: $
[0 - Gt; Resource 1 - & gt; Resources 2 - & gt; Resource $ promise - & gt; Object $ solution - & gt; True]
The callback does nothing and the event is not placed on the calendar.
I also tried to put in the configuration to see this function.
$ scope.uiConfig = {calendar: {height: 450, editable: true, header: {left: 'title', center: '', right: 'today back, next' }, EventClick: $ scope.alertOnEventClick, viewRender: function (see, element) {$ scope.surgeries = SurgerySource.jsonp_query ({start: view.visStart.getTime () / 1000, end view.visEnd.getTime () / 1000}); Console.log ($ scope.surgeries); }}}; $ Scope.surgeries = []; $ Scope.eventSources = [$ scope.surgeries];When I open the calendar I see the data, but the events are not populated in the calendar.
So I need to know how to get the date range out of the calendar view, so I can use my hard coded method. Or I need to know how to get the resource data from the promise (?) Object and send it to $ scope.eventSources
I got this job by switching to $ http instead of creating a service. My new event source function looks like this
$ scope.eventSource = function (start, end, callback) {var startDate = start.getTime () / 1000; Var End date = End. Jet Time () / 1000; Var url = 'http://api.mydomain.com/app_dev.php/calendar.json?callback=JSON_CALLBACK&start='+startDate+'&end='+endDate; $ Http.jsonp (url) .then (function (response) {callback (response.data);}); };
I also had to make sure that my source was sending my timestamp instead of strings.
Comments
Post a Comment