ActiveRecord for AngularJS
angular-activerecord is a Backbone.Model inspired modellayer for AngularJS.
Differences compared to Backbone.Model
- No attributes property.
- Because the properties and methods are on the same level the ActiveRecord methods & config-properties are prefixed with "$" to prevent naming collisions.
- Stripped out functionality that is provided by angular)
- No getter/setter methods. (Angular has $scope.$watch)
- No event system. (Angular has $scope.$emit)
- No dependency on underscore. (angular.extend, angular.isFunction, etc)
- No dependency on jQuery. (Angular has $http)
- No Collection class. (Angular works with plain javascript array's)
- Added static fetchOne(id) and fetchAll() class-methods.
- Added read & write filtering of properties through angular filters.
Goals / Features (compared to ngResource)
- Extendable OOP designed models (instance methods per type)
- Enable parsing the response.
- Allow default values.
- Allow alternative backends.
- Allow alternative url schemes (like a .json suffix)
- Minimal configuration (only a $urlRoot), the json-object from the rest-api is the spec.
Examples
Defining a model
module'myApp' 'ActiveRecord'; // Add "ActiveRecord" as module dependency. module'myApp'
Fetching and saving data.
module'myApp';
Loading models via ngRoute
module'myApp' 'ngRoute'; module'myApp';