From a2a6f29592e5699ce117e4a0154ad2b4484f18a9 Mon Sep 17 00:00:00 2001 From: Daniele Morosinotto Date: Fri, 12 Jun 2020 10:59:35 +0200 Subject: [PATCH] =?UTF-8?q?docs:=20=E2=9C=8F=EF=B8=8F=20clarify=20config?= =?UTF-8?q?=20errors=20usage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now you can pass to the errors property in config an `HashMapstring>` so you can specify the error message directly as a simple string, or with a function that will return the message string based on the error. BREAKING CHANGE: No --- .all-contributorsrc | 20 +++++++++++++++++++ README.md | 13 +++++++----- .../src/lib/control-error.directive.ts | 1 + 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index 832322a..b3957f3 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -31,6 +31,26 @@ "code", "test" ] + }, + { + "login": "theblushingcrow", + "name": "Inbal Sinai", + "avatar_url": "https://avatars3.githubusercontent.com/u/638818?v=4", + "profile": "https://github.com/theblushingcrow", + "contributions": [ + "doc" + ] + }, + { + "login": "dmorosinotto", + "name": "Daniele Morosinotto", + "avatar_url": "https://avatars2.githubusercontent.com/u/3982050?v=4", + "profile": "https://twitter.com/dmorosinotto", + "contributions": [ + "code", + "doc", + "example" + ] } ], "contributorsPerLine": 7 diff --git a/README.md b/README.md index 11ccab1..d34388e 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ Sit back, relax, and let the Error Tailor do all the work! Run `ng add @ngneat/error-tailor`. This command updates the `AppModule`, and adds the `ErrorTailorModule` dependency: + ```ts @NgModule({ declarations: [AppComponent], @@ -32,8 +33,9 @@ Run `ng add @ngneat/error-tailor`. This command updates the `AppModule`, and add ErrorTailorModule.forRoot({ errors: { useValue: { - required: error => `This field is required`, - minlength: ({ requiredLength, actualLength }) => `Expect ${requiredLength} but got ${actualLength}`, + required: 'This field is required', + minlength: ({ requiredLength, actualLength }) => + `Expect ${requiredLength} but got ${actualLength}`, invalidAddress: error => `Address isn't valid` } } @@ -43,8 +45,9 @@ Run `ng add @ngneat/error-tailor`. This command updates the `AppModule`, and add }) export class AppModule {} ``` + -The `errors` config property takes a partial `Provider`, that should provide an object containing the form errors. +The `errors` config property takes a partial `Provider`, that should provide a `HashMap< string | (err:any) => string >` that is an object with keys corresponding to the errors name that you want to handle, and values that can be a simple string, or function that return a string used as error message to be shown. Now the only thing you need to add is the `errorTailor` directive to your form: ```html @@ -232,13 +235,13 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Netanel Basal

💻 📖 🤔 🚇
Toni Villena

💻 ⚠️ -
Inbal Sinai

📖 +
Inbal Sinai

📖 +
Daniele Morosinotto

💻 📖 💡 - This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome! diff --git a/projects/ngneat/error-tailor/src/lib/control-error.directive.ts b/projects/ngneat/error-tailor/src/lib/control-error.directive.ts index c8b07fb..d9104a9 100644 --- a/projects/ngneat/error-tailor/src/lib/control-error.directive.ts +++ b/projects/ngneat/error-tailor/src/lib/control-error.directive.ts @@ -96,6 +96,7 @@ export class ControlErrorsDirective implements OnInit, OnDestroy { ngOnDestroy() { this.destroy.next(); if (this.ref) this.ref.destroy(); + this.ref = null; } private valueChanges() {