khashayar / ng-trim-value-accessor

Angular's (missing) trim accessor to automatically trim values of input fields
MIT License
53 stars 19 forks source link

Add forRoot Method to TrimValueAccessorModule #28

Closed nulayuhz closed 5 years ago

nulayuhz commented 5 years ago

Hi,

When I import this module, components in my child modules are not getting the directive applied. So I import it to each of my module and then it works. I have not tested but I suspect if you add the forRoot method that can fix this issue.

Thanks

khashayar commented 5 years ago

Thanks for submitting the PR for this, but before merging it, can you please elaborate more on your issue? What version of Angular are you using? Are you importing it in the AppModule? Can you share a code sample?

Regarding the fix with the forRoot, here's a quote from Angular's doc page:

Use forRoot() to separate providers from a module so you can import that module into the root module with providers and child modules without providers.

I'm not sure that's exactly what we need here but it's good to know whether you've tested your solution and if it solves the issue.

nulayuhz commented 5 years ago

Hi, I am using Angular 5, the issue I am having is when I import it under AppModule, the value accessor is not working in components in the child modules. Sorry for creating a PR without testing, let I verify and do some testings.

khashayar commented 5 years ago

I'm using it currently in Angular 7 and importing this module inside the SharedModule and exporting it back. This way it's accessible through the feature modules.

nulayuhz commented 5 years ago

You are right about the SharedModule export, that was the thing I was missing, thank you.

zolakt commented 2 years ago

Is there any other solution for this?

Using the SharedModule is a workaround. Basically the same as importing it directly in every child module, just with less scattered code. It is not applicable to a lot of use cases.

For example, I have 3 apps: 1 library project, and 2 apps that use the library. Inside the library there are some textareas that I want trimmed. In the 1st app I want to use the trimming, but not in the 2nd app. So, I can't push this module import all the way down to the library project. I want to import it only in the AppModule of the 1st app.