Is it necessary to click and select the dropdown value to get it through valueChanges in angular?

Viewed 29

I am creating an angular reactiveForm. The same form is used for add and edit funcationality. In add, the respective values are obtained through valueChanges with dropdwon selection without any problem. But in the edit mode, when an employee selected, his previous data is automatically loaded into the form. Then you can update desired fields. Now after selecting the emp id in this form , the corresponding value for emp name will be filtered and obtained automatically in the edit mode. enter image description here

But the issue is valueChanges will not fire here. When I go to submit the form with automatically set value like above, an arror appears saying that the emp name is empty. After I click on the dropdwon and select, I get the value for FormArray correctly. My question is when setting value for this dropdown, can we fire valueChanges and set the value by clicking the dropdown only?

`

     jobDetailsData = <any>{};
     
     this.empDetailsData = await firstValueFrom(this.empService.getEmpDetails(this.empId));  // get data from endpoint
     
        for (let i = 0; i < this.jobDetailsData.emp_context.length; i++) {
        const empContext = this.createEmpForm.get('emp_context') as FormArray;
        this.EmpList = this.EmployeeList.filter(....);
        const EmpNameId = this.EmpList.find(...)?.id;
        
        empContext.insert(0, this.formBuilder.group({
            .....,
            emp_id: [EmpNameId]    // Appear in the dropdown but not in here
        }));
        
        }

`

0 Answers
Related