ngneat / error-tailor

🦄 Making sure your tailor-made error solution is seamless!

Home Page:https://netbasal.com/make-your-angular-forms-error-messages-magically-appear-1e32350b7fa5

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The differenece in useValue / useFactory

mlc-mlapis opened this issue · comments

I'm submitting an ...

[x] Documentation issue or request

Current behavior

In our case, we tried to use error-tailor package in the situation when it is used inside a lazy-loaded module (loaded programmatically) and error-tailor was imported only on that level and not on the main app module level.

If it is used the following code with useFactory, it works as expected.
If it is used with useValue, it doesn't work. It would be probably helpful for others to explain those two variants explicitly in detail.

@NgModule({
   declarations: [...],
      imports: [
         CommonModule,
         ReactiveFormsModule,
         ErrorTailorModule.forRoot({
            errors: {
               useFactory() {
                  return {
                     required: () => `This field is required`,
                     minLength: ({requiredLength, actualLength}) => `Expect ${requiredLength} but got ${actualLength}`,
                     invalidAddress: () => `Address not valid`
                  };
               }
            }
         }),
      routing,
      ...
]
})
export class LazyLoadedModule {...}

It is a typo. Check the new PR.