Validation using if statement using input binding in Angular

Shivam Manandhar

I am creating a reusable component for Input field. I created a Boolean tag named "IsValid" inside my typescript file to show validation message.

My typescript file

export class InputControlsComponent implements OnInit {

  @Input() IsValid;
  @Input() className;
  @Input() controlName;
  @Input() inputType;

  constructor() { }

  ngOnInit() {
  }

}

Html File

<div>
  <input type="{{inputType}}" class="{{className}}" >
  <span class="error-message" *ngIf="!IsValid">This Field is required</span>
</div>

How it is being used

<div>
          <label>Name</label>
          <app-input-controls  inputType="text"  controlName="Address" className="form-control" IsValid = "false">
          </app-input-controls>
</div>

I am able to change the value of the Boolean tag of typescript file but the error message is not changing on change of the Boolean tag.

ahmeticat

You can use ngModel like [(IsValid)],

If you use ngModel,your model is binding two way.

For example set your html

<app-input-validation  [inputType]="'text'"  [controlName]="Address" [className]="form-control" [(IsValid)]="isValidDate">
</app-input-validation>

You can set isValid property on parent component whenever you want.

Only write this.isValidText=true;

Please examine example

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Input validation using jQuery

From Dev

How to pass data to the input in angular html component using property binding

From Dev

Binding data to another component and use it in angular using @Input, @Output and EventEmitter

From Dev

Angular @Input binding using function calling multiple times

From Dev

Is there a convention for using Angular brackets binding notation for @Input properties?

From Dev

How to get form input, select value using Angular Binding?

From Dev

How to give validation for input field using angular2 in primeng

From Dev

Using reactive form validation with <input type="file"> for an Angular app

From Dev

add custom validation in input type text using angular material stepper

From Dev

Angular Reactive Forms Dynamically Generating Validation Attribute on Input using Interpolation

From Dev

User input Validation using PowerShell

From Dev

Input validation (java) using GUI

From Dev

Input Validation using Multiple Regex

From Dev

Input validation using a separate method

From Dev

Input validation while using streams

From Dev

$event binding in angular using PrimeNG

From Dev

Binding not working using angular on Ionic

From Dev

Is using input() in an if statement a bad practice?

From Dev

Binding not work when initial the context with USING Statement

From Dev

UPDATE statement not working when using binding

From Dev

How to create custom input component with validation using angular material inputin Angular14?

From Dev

Using '&&' operator for angular validation in thymeleaf

From Dev

Form validation using angular 2

From Dev

Dropdown validation using Angular Js

From Dev

Issues with using "IF" statement and empty cells in Data Validation

From Dev

What does using parentheses instead of quotes do when binding input data to an Angular component in the template?

From Dev

How to set the value of date input field using data binding in Angular 5?

From Dev

Binding input type using refs in reactjs

From Dev

Adding validation in an input field for options selected using Template driven forms in angular 13

Related Related

  1. 1

    Input validation using jQuery

  2. 2

    How to pass data to the input in angular html component using property binding

  3. 3

    Binding data to another component and use it in angular using @Input, @Output and EventEmitter

  4. 4

    Angular @Input binding using function calling multiple times

  5. 5

    Is there a convention for using Angular brackets binding notation for @Input properties?

  6. 6

    How to get form input, select value using Angular Binding?

  7. 7

    How to give validation for input field using angular2 in primeng

  8. 8

    Using reactive form validation with <input type="file"> for an Angular app

  9. 9

    add custom validation in input type text using angular material stepper

  10. 10

    Angular Reactive Forms Dynamically Generating Validation Attribute on Input using Interpolation

  11. 11

    User input Validation using PowerShell

  12. 12

    Input validation (java) using GUI

  13. 13

    Input Validation using Multiple Regex

  14. 14

    Input validation using a separate method

  15. 15

    Input validation while using streams

  16. 16

    $event binding in angular using PrimeNG

  17. 17

    Binding not working using angular on Ionic

  18. 18

    Is using input() in an if statement a bad practice?

  19. 19

    Binding not work when initial the context with USING Statement

  20. 20

    UPDATE statement not working when using binding

  21. 21

    How to create custom input component with validation using angular material inputin Angular14?

  22. 22

    Using '&&' operator for angular validation in thymeleaf

  23. 23

    Form validation using angular 2

  24. 24

    Dropdown validation using Angular Js

  25. 25

    Issues with using "IF" statement and empty cells in Data Validation

  26. 26

    What does using parentheses instead of quotes do when binding input data to an Angular component in the template?

  27. 27

    How to set the value of date input field using data binding in Angular 5?

  28. 28

    Binding input type using refs in reactjs

  29. 29

    Adding validation in an input field for options selected using Template driven forms in angular 13

HotTag

Archive