I am facing challenges while attempting to create a Factory in AngularJS. I have moved the code from the controller to the factory and made a few adjustments for it to function properly.
Here is the error that I am encountering:
"El objeto no acepta la propiedad o el método 'addPoint'" (in IE) ("Object does not support property or method 'addPoint'")
"Uncaught TypeError: undefined is not a function" (in Chrome)
Below is my code snippet:
function Shape(shape) {
this.ToolName = shape.tool;
this.LineColor = shape.lineColor;
this.LineWidth = shape.lineWidth;
this.LineCap = shape.lineCap;
this.FillStyle = shape.fillStyle;
this.isFilled = shape.filled;
this.isStroked = shape.stroked;
this.Points = [];
}
Shape.prototype.addPoint = function(point){
if(this.ToolName!=='pencil' && this.Points.length>1){
this.Points.pop();
}
this.Points.push(point);
};
This functionality used to work when it was placed inside the Controller, but now it is not functioning as expected within the factory.
Thank you.
EDIT:
I apologize for not providing more code. You can find the source code here: https://github.com/michaeljota/Arheados/blob/master/app/scripts/controllers/main.js
The code above pertains to the controller section. My objective is to convert everything that is not handled by $scope into a Factory. Someone suggested using a Service, but I am not fully familiar with how Services operate.
Thank you once again!