My situation involves a factory with a series of prototypes that need to call each other. The issue arises when the reference to "this" is mistakenly applied to the html template instead of the original factory class when using ng-click
.
For example:
angular.factory('myFactory', function(){
function FactoryA(){}
FactoryA.prototype.hello = function(){ console.log('Hello') };
FactoryA.prototype.useHello = function(){ this.hello() };
return FactoryA;
}
In the controller, the factory is set to the $scope variable "myFactory".
The ng-click
in the html template would look like this:
<button type="button" ng-click="myFactory.useHello()">Hello</button>
The problem lies in the fact that "this" within myFactory.useHello now refers to the html template rather than maintaining its connection to FactoryA and its other prototypes.
How can I ensure that ng-click functions remain associated with the factory class and its other prototypes?