Vijay Gajera
Vijay Gajera

Reputation: 1364

How to disable reactive form property in angular 2

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

Upvotes: 0

Views: 736

Answers (1)

Chrillewoodz
Chrillewoodz

Reputation: 28318

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();

Upvotes: 2

Related Questions