Understanding Factory provider parameter in angular4

时间:2018-01-23 19:27:08

标签: angular angular-factory

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 'foo@yahoo.com'; }, 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 'foo@yahoo.com';
}; 

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 'foo@yahoo.com';
  };
};

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

0 个答案:

没有答案