1

I created FormGroup and initialized FormGroup with one formControlName (SerialNumber). SerialNumber JSON looks like this:

{
    "SerialNumber": {
        "snValue": "332432"
    }
}

I don't know how to bind SerialNumber.snValue to the <input>. I always get [object Object] instead of 332432.

.ts code

equipmentForm: FormGroup;
constructor(private fb: FormBuilder) {}
ngOnInit(): void {
     this.equipmentForm = this.fb.group({
     serialNumber: {"snValue": "332432"}
     })
}

.html

<input type="text" formControlName="serialNumber" />

My question is, how to bind snValue?

enter image description here

1
  • 1
    If you're going to use FormBuilder, use it properly. See: angular.io/guide/…. Commented Oct 17, 2021 at 11:36

1 Answer 1

1

Let's say you already have your object obj, you can do this :

obj = {
  "SerialNumber": {
    "snValue": "332432"
  }
};

ngOnInit(): void {
   this.equipmentForm = this.fb.group({
     serialNumber: [obj.SerialNumber.snValue]
   });
}
Sign up to request clarification or add additional context in comments.

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.