I have a requirement in which i should write factory. This factory should contain 3 function init, save and delete
I should call init function from controller. This function returns an object. This object has the function to execute the add and delete function.
how can i achieve this?
Following is my code, It execute the init function successfully but when i try to use the object which was returned in add or delete, it says object is empty
angularApp.factory('SomeFactory', function(){
var client = new Client(); // this client is defined in another javascript file
// this is the object which we should return
var clientReady = function () {
var cv = client.GetVersion();
showIDs();
};
return {
initClient:function(requiredUID){
client.setAttribute("clientReadyCallback",clientReady);
}//,
};
var add = function () {
client.someapi;
};
var delete = function () {
client.someapi;
};`
});
in controller i call the below calls
SomeFactory.initClient("username");
SomeFactory.add();// throws error
How can i achieve this?
var add = function() ...because you are returning before it.