Skip to content

Commit

Permalink
chore(readme): add new docs for hasError conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
toddmotto committed Apr 13, 2017
1 parent 38a8e03 commit 3ad99fb
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ The `getError` method returns the object associated with your error. This can be

> The error returned is identical to Angular's FormControl API
#### hasError(name: string): boolean;
#### hasError(name: string, conditions?: string | string[]): boolean;

The `hasError` method informs you if your control has the given error. This can be useful for styling elsewhere in your template based off the control's error state.

Expand All @@ -235,6 +235,22 @@ The `hasError` method informs you if your control has the given error. This can
</div>
```

You can optionally pass in conditions in which to activate the error.

> Example: Adds `class="required"` when "myError" has the `required` error _and_ the states are `'dirty'` and `'touched'`.
```html
<div [ngClass]="{ required: myError.hasError('required', ['dirty', 'touched']) }">
<input type="text" formControlName="username">
</div>

<div ngxErrors="username" #myError="ngxErrors">
<div ngxError="required" [when]="dirty">
Field is required
</div>
</div>
```

#### hasErrors: boolean;

The `hasErrors` property returns `true` if your control has any number of errors. This can be useful for styling elsewhere in your template on a global control level rather than individual errors.
Expand Down

0 comments on commit 3ad99fb

Please sign in to comment.