AngularJS: Creating Objects that map to REST Resources (ORM-Style)

前端 未结 7 571
南笙
南笙 2021-01-29 18:09

I\'m pretty new to AngularJS, but I\'m pretty unclear on how to tie it up to my Server\'s REST Api backend.

For example, say I have an \"image\" resource that I get by G

7条回答
  •  花落未央
    2021-01-29 18:36

    After lots of research, here is a comprehensive list of all the solutions available:

    • Restmod

    • Modelizer

    • ModelCore

    • angular-watch-resource

    • angular-restful

    • ngResource

    • angularjs-rails-resource

    • angular-nested-resource

    • Aar.js

    • Angular Activerecord

    • Angular-Data

    • ngActiveResource

    • restangular

    • BreezeJS

    • ng-backbone

    but honestly I wasn't very happy, so I decided to add to the list my own solution haha. Check it out here: $modelFactory.

    Your end-result code ends up looking something like:

    var module = angular.module('services.zoo', ['modelFactory']);
    
    module.factory('AnimalModel', function($modelFactory){
      return $modelFactory('api/zoo');
    });
    
    return module;
    

    I believe this is a better solution over the rest because mainly the model definition closely resembles Angular's ngResource, adding just low-level features one needs that it lacks. Its super lightweight (1.45k gzip/min) and has only a few small dependencies ( no lodash, jquery, etc ).

提交回复
热议问题