سؤال

How do I connect a AngularJS app to a Kinvey backend in an easy way?

هل كانت مفيدة؟

المحلول 2

A bit late to the conversation, but I have created a library for AngularJS that provides full support to Kinvey using the REST API.

https://github.com/ninjatronic/angular-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).

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top