0

I have one reactive form and i take one array inside form my implementation is like

testForm:FormGroup;

fb is instance of FormBuilder;

this.testForm=this.fb.group({

testarray:this.fb.Array([
note:['']
])
})

I am using above array on my html to display note. Here functionality is like user can add multiple note.

I want to disable and enable note of array when i post not at that time want to identify which not is posted and need to disable that note.

Here my question is how can we disable reactive form array property using angular 2 typescript?

Please help me Thanks

1 Answer 1

2

For starters this:

testarray:this.fb.Array([
  note:['']
])

is not valid syntax, you're trying to assign a note property to an array. I think what you want is this (also notice the lowercase a in array):

testarray: this.fb.array([
  this.fb.control('')
])

Then when you want to disable a control in the array you can simply call .disable()on it.

So let's say you have a control:

const myControl = this.testForm.get('testarray').controls[0];

You would do

myControl.disable();
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.