Models - adrianlee44/ng-backbone GitHub Wiki

Model

APP.factory('MyModel', ['NgBackboneModel', function (NgBackboneModel) {
  return NgBackboneModel.extend({
    urlRoot: '/my-models',
   
    constructor: function MyModel() {
      // ...

      NgBackboneModel.apply(this, arguments);
    },
 
    initialize: function () {
      // ...

      // must be called when overriding initialize()
      NgBackboneModel.prototype.initialize.apply(this, arguments);
    }
  });
}]);

Fetching

APP.controller('MyController', ['$scope', 'MyModel', function ($scope, MyModel) {
  // my_model.constructor.class === 'MyModel'
  var my_model = new MyModel();

  // $http promise
  my_model.fetch({
    error: function (model, response, options) {},
    success: function (model, response, options) {}
  });
}]);

Status

| Method | Status | Before| onCreate | onDelete | onFetch | After | | --- | --- | --- | --- | --- | --- | --- | --- | | my_model.destroy() | my_model.$status.deleting | false | false | true | false | false | | my_model.fetch() | my_model.$status.loading | false | false | false | true | false | | my_model.save() | my_model.$status.saving | false | true | false | false | false | | any method | my_model.$status.syncing | false | true | true | true | false |

Events