JSFiddle - React, Tailwind, and code Playground
HTML
<div ng-app="app" ng-controller="ctrl as vm">
<div>
{{ vm.infoFactory.gasmeter.url }}
</div>
<button ng-click="vm.change()">Change URL</button>
<button ng-click="vm.reset()">Reste</button>
</div>
JavaScript
var mainapp = angular.module('app', []);
mainapp.controller('ctrl', function(infoFactory) {
var vm = this;
vm.infoFactory = infoFactory;
vm.change = function() {
vm.infoFactory.gasmeter.url = "new url";
};
vm.reset = function() {
vm.infoFactory.reset();
};
});
mainapp.factory("infoFactory", function(){
// Save a reference to the current pointer of the factory, so you won't loose it inside other scopes
var self = this;
self.params = {
ArrayInfo: {},
placeholders: {},
gasmeter: {},
gasmeter1: {},
ArrayInfo: false,
RawDate: {},
Dates: {}
};
self.reset = function() {
self.params.ArrayInfo = {};
self.params.placeholders.licenseone = "img/placeholder.png";
self.params.gasmeter.url = "img/gas/gas1.png";
self.params.gasmeter.gasvalue = "1";
self.params.gasmeter1.url = "img/gas/gas1.png";
self.params.gasmeter1.gasvalue = "1";
self.params.ArrayInfo.returned = false;
self.params.RawDate = {};
self.params.Dates = {};
}
self.reset(); // Call this function by default in order to initially set the factory properties
return {
reset: self.reset, // You can export the reset function and use it outside the factory too
ArrayInfo: self.params.ArrayInfo,
gasmeter: self.params.gasmeter,
gasmeter1: self.params.gasmeter1,
placeholders: self.params.placeholders,
RawDate: self.params.RawDate,
Dates: self.params.Dates
};
})