Skip to content

Instantly share code, notes, and snippets.

@bobey
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bobey/416e2ec23dd8a716399a to your computer and use it in GitHub Desktop.
Save bobey/416e2ec23dd8a716399a to your computer and use it in GitHub Desktop.
Angular model with factory
/* @ngInject */
function GouzigouzaController($scope, Gouzigouza) {
$scope.gouzigouza = new Gougigouza({
code: 'CODE'
});
}
angular
.module('my.namespace.controllers')
.controller('GouzigouzaController', GouzigouzaController);
function GouzigouzaFactory() {
var Gouzigouza = function Gouzigouza (data) {
this.id: data.id;
this.code: data.code;
};
Gouzigouza.prototype = {
/**
* @returns {boolean}
*/
isNew: function() {
return !this.id;
}
};
return Gouzigouza;
}
angular
.module('my.namespace.resources')
.factory('Gouzigouza', GouzigouzaFactory);
@youknowriad
Copy link

function GouzigouzaFactory() {

 return Class.extend({

      init: function(config) {
          this.id = config.id
          this.code = config.code
      },

      isNew: function() {
          return !this.id;
      }
 });

}

angular
.module('my.namespace.resources')
.factory('Gouzigouza', GouzigouzaFactory);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment