[英]How to connect a AngularJS app to Kinvey?
如何以简单的方式将AngularJS应用连接到Kinvey后端?
Disclaimer: I work at Kinvey. 免责声明:我在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. 我一直在开发一个在业余时间使用angular的应用程序,您可以看到我创建的与Kinvey通信的服务的源代码。 https://github.com/InnCrisis/InnCrisis/blob/master/public/coffeescripts/adminServices.coffee
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. 一小段JavaScript代码,用于处理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. 由于Kinvey javascript API会进行角度无法跟踪的更改,因此需要对结果执行$ scope。$ apply。
Based on a quick tour of their site, it seems Kinvey has a RESTful API, which makes things fairly straightforward. 通过快速浏览他们的网站,Kinvey似乎拥有RESTful API,这使事情变得相当简单。 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).
要进行跨域访问,您需要确定Kinvey服务器是否符合CORS标准 (返回允许跨域访问的适当标头),否则,您需要使用Angular的$ http.jsonp来获取数据( jsonp仅支持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. 谈话有点晚了,但是我为AngularJS创建了一个库,该库使用REST API为Kinvey提供了完全支持。
https://github.com/ninjatronic/angular-kinvey https://github.com/ninjatronic/angular-kinvey
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.