Understanding Factory provider parameter in angular4

320 Views Asked by At

I am confused with the parameter for the factory provider in angular4. suppose if i am using a factory provider like this

scenerio 1

{ 
provide: PREFERRED_BOOKS, 
useFactory: () => { return '[email protected]'; }, deps: [Book, BookService] 
}

now, the useFactory provider is a function, and we are returning a string

scenario 2

if i do the same thing like this

 { 
provide: PREFERRED_BOOKS,
 useFactory: preferredBooksFactory(), deps: [Book, BookService] 
}

function preferredBooksFactory() {
  return '[email protected]';
}; 

I am getting compilation error, where i shouldnt be getting compilation error because all i did was passed a function to the provider

scenario 3

when i change my function like this, then it works fine

export function preferredBooksFactory() {
  return (): string => {
    return '[email protected]';
  };
};

can anyone please explain me what is happening and what am i missing

0

There are 0 best solutions below