The inputError directive

The basic idea is the definition of an inputError directive that would enable a syntax similar to this one:

<div *inputError="let error from quantity.errors">    {{error}}</div>

Here, quantity is a template reference bound to the ngModel input field with #quantity="ngModel", so that quantity.errors is an object whose properties are the names of all error detected. The directive chooses just one of the error names and uses it to select an adequate error message. Then, it binds this error message to the $implicit context object property so that the error message is assigned to the error variable. quantity.errors will be bound to a directive input property named inputErrorFrom. The use of a div is just an example, since ...

Get Hands-On TypeScript for C# and .NET Core Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.