Inside an AngularJS module I\'m developing, I have a Canvas
class defined as:
angular.module(\"myModule\", [])
.factory(\"Canvas\", function() {
I figured it out:
angular.module("myModule", [])
.factory("Canvas", ["$q", function(q) {
Canvas.prototype.q = q;
return Canvas;
}]);
var Canvas = function(element, options) {
console.log(this instanceof Canvas, typeof this.q !== "undefined");
};
This logs: true true
.
I create Canvas service like this and is work:
var app = angular.module('myModule', []);
app.factory("Canvas", ["$q", function($q) {
var Canvas = function(element, options) {
this.q = $q;
this.init();
console.log(this.q, element, options);
}
Canvas.prototype.init = function() {/*...*/};
Canvas.prototype.otherMethod = function() {/*...*/};
return Canvas;
}]);
app.controller('MainCtrl', ['$scope', 'Canvas', function($scope, Canvas) {
console.log( new Canvas().q );
}]);
Also you can see this on Pluncer here