0

How to make "passed out year" field disable if the degree is not typed. May I know can we achieve it in html without .ts file use.

  <div>  Degree:                    
  <input type="text" class="form-control" formControlName="degree" #degree/></div>

<div>
Passed Out Year
  <input type="text" class="form-control" formControlName="passedYear"/></div>

2 Answers 2

1

Add this [disabled]="!formName.controls['degree'].value" in case you want any value, or this [disabled]="!formName.controls['degree'].valid" in case you want passedyear to be entered correctly.

However, if you need to implement more complex checks you may want to add custom validators.

Sign up to request clarification or add additional context in comments.

2 Comments

you could even shorten it to degree.value i think because he has the #degree
sure, I also made a mistake, in case you want to disable 'passedYear' input, you have to check 'degree'
0

It's not clear exactly how you are planning to use this, but you may not need to use Angular Forms if you're doing something simple. In that case you can accomplish what you need by just using ngModel like this

<div> Degree:
    <input type="text" class="form-control" [(ngModel)]="degree" />
</div>

<div>
    Passed Out Year
    <input type="text" class="form-control" [disabled]="!degree" />
</div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.