I've been planning on using Kinvey as the backend for my upcoming Kids In Touch app. Today, I finally got to the point of beginning integration with the client to the backend.
During some initial testing, I could not figure out how to integrate the promises that Kinvey uses with the promise library that AngularJS uses. I was struggling to use the deferred result after the Kinvey promise completed.
See this example : http://jsfiddle.net/justbn/EVq85/7
The controller has a "KinveyTest" service injected. The KinveyTest service has 2 public methods "pingKinveyNoReturn" and "pingKinveyWithResult"
When you click the "Simple Ping" button, it just triggers the controller to call the KinveyTest.noReturnPing method. This method is an example ping straight out of your docs.
When the "Complex Ping" button is clicked, it triggers Kinvey.needResultOfPing via the controller. In this method, I want to use Angular's $q promise library to wait for Kinvey to return a response from a ping. Once that is finished, I want the public method in KinveyTest to get the results of the Kinvey promise. Unfortunately, this never works.
After sending a request to Kinvey support, the light bulb finally turned on. I played with it some more and solved it. The problem is the usual AngularJS digest. It's not updating after the Kinvey promise completes. The solution is the ugly $rootScope.$apply() method.
This may not be the prettiest was to deal with Kinvey & AngularJS promises, but it's the best I could come up with.
Here's the working solution:
http://jsfiddle.net/justbn/EVq85/8/
- Signup to find out when Kids In Touch launches