I am trying to pass input parameters from one function to another function inside a return statement. However in below example input1 and input2 are undefined. The values inside the return statement are undefined while inside the factory function they are not. How do I pass the values into the returned func()?
function func(input1,input2) {
console.log(input1,input2)
// "undefined, undefined"
}
angular.module("factory").factory("test", (input1, input2) => {
console.log(input1, input2)
//"input1", "input2"
return {
func: (input1, input2) => {
func(input1, input2);
}
};
});
func()method you return takes its owninput1andinput2which shadow theinput1andinput2from the parent function. If you don't need parameters for the methods, just remove them and thefuncfunction will use the outer ones.func :function is not the same as outside it. It is a local param. You can omit input1,and input2 from the definition.