如何以简单的方式将AngularJS应用连接到Kinvey后端?
Disclaimer: I work at Kinvey.
I have been working on an app that uses angular in my free time, you can see the source to the services I have created that communicate with Kinvey. https://github.com/InnCrisis/InnCrisis/blob/master/public/coffeescripts/adminServices.coffee
A small snippet of javascript to handle the registration of a new user in Kinvey.
register = function(username, password, name) {
var deferred = $q.defer();
new Kinvey.User.create({
username: username,
password: password,
name: name
}, {
success: function(user) {
$rootScope.$apply(null, function() {
deferred.resolve(user.toJSON(true));
});
},
error: function(e) {
$rootScope.$apply(null, function() {
deferred.reject(e);
});
}
});
return deferred.promise;
}
Since the Kinvey javascript API will make changes that are not tracked by angular you need to do a $scope.$apply of the results.
Based on a quick tour of their site, it seems Kinvey has a RESTful API, which makes things fairly straightforward. Going cross-domain, you'll need to find out if the Kinvey server is CORS compliant (returns appropriate headers allowing for cross-domain access) or if not, you'll need to use Angular's $http.jsonp to GET the data (jsonp only supports GET).
A bit late to the conversation, but I have created a library for AngularJS that provides full support to Kinvey using the REST API.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.