2

I am using Angular version 6. When I run the below code it works

<input type="text" class="form-control" id="designation" value="sample"   />

I need to get this default value ("sample") from text box, so then I changed this code to

<input type="text" class="form-control" id="designation" value="sample" [(ngModel)]="addRequisitionss.designation"  name="designation" #designation="ngModel"  />

When I executed above code value "sample" is not showing in text box.

I am trying to display default value("sample") in the text field, and I have to fetch that value("sample"), any suggestions?

2 Answers 2

3

When you have ngModel on an input tag, it takes preference over the value attribute. So it is good to initialise value with ngModel variable itself.

<input type="text" class="form-control" id="designation" [(ngModel)]="addRequisitionss.designation"  
 name="designation" #designation="ngModel"  />

ts code :

addRequisitionss.designation = 'sample';
Sign up to request clarification or add additional context in comments.

Comments

1

You can simply make the default value like that:

component.html

<input type="text" class="form-control" id="designation [(ngModel)]="addRequisitionss.designation"  name="designation" />

and in component.ts make the dafault value

addRequisitionss.designation = "default value"

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.