javascript - Angular custom module - "object function(){...} foo has no method 'bar'" -


i'm trying create custom wrapper $http in angular. here's code outline:

angular.module('jotted_resource', ['ng']) .factory('jotted_resource', ['$http', 'communicationstatus',     function($http, cs) {         function jresourcefactory(url){             function jresource(value){                 var self = this;                 this.query = function(callback){                     var value = [];                     return $http.get(url).then(function(response){                         var data = response.data;                         for(var in data){                             value.push(new jresource(data[i]))                         }                     });                     return value;                 }             }             return jresource;          }         return jresourcefactory;     } ]);  

but example code this:

app.factory("label", ["jotted_resource", function(jotted_resource) {    var label = jotted_resource("api/labels");    var = label.query();    ... 

throws error saying:

typeerror: object function jresource(value){ ...} has no method 'query'

i'm afraid knowledge on complexities of javascript's objects/functions/prototypes isn't sufficient enough wrap head around issue. please point out how can fix code.

this pure javascript issue. since label function , need use new keyword create object in order make prototype inheritance work.

var = (new label()).query(); 

Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -