Dear Sir/Madam,

I need my MAT-SELECT component to be populated when I enter the form. 
However, the value never gets set.

The HTML File contains the following code:

<mat-form-field>
<mat-select placeholder="Select Parent Module" formControlName=
"parentModule" [(value)]="selectedParentModule">
<!-- <mat-select placeholder="Parent Module" formControlName="parentModule" 
[(ngModel)]="selectedParentModule"> -->
<mat-option>None</mat-option>
<mat-option *ngFor="let module of moduleListDisplayed" [value]="module">
{{module.moduleName}}</mat-option>
</mat-select>
</mat-form-field>

The .TS File contains the following:


ngOnInit() {
this.dataForm = new FormGroup({
'moduleCode': new FormControl(null, {validators: [Validators.required, 
Validators.maxLength(10)]}),
'moduleName': new FormControl(null, {validators: [Validators.required, 
Validators.maxLength(255)]}),
'parentModule': new FormControl(null, {validators: [Validators.maxLength(10
)]}),
'parentModuleName': new FormControl(null, {validators: [Validators.maxLength
(255)]}),
'updateUser': new FormControl(null, {validators: [Validators.maxLength(20
)]})
});
this.dummyData = {
moduleCode: '',
moduleName: '',
parentModule: '',
parentModuleName: '',
updateUser: this.dataService.loggedInUser
};

// Get the list of available modules and populate in Parent Module
this.dataService.getData();
this.parentSubscription = this.dataService.getDataUpdatedListener()
.subscribe( (data: Module[]) => {
this.moduleList = data;
// this.refresh();

// Display the current Record
this.route.paramMap.subscribe((paramMap: ParamMap) => {
if (paramMap.has('moduleCode')) {
this.mode = this.EDIT_MODE_INDICATOR;
this.dataCode = paramMap.get('moduleCode');
this.dataService.getOneData(this.dataCode)
.subscribe(fetchedData => {
this.dataToEdit = fetchedData.data;
this.moduleListDisplayed = [...this.moduleList
.filter(parentData => parentData.moduleCode !== this.dataCode)];
this.dataForm.setValue({
'moduleCode': this.dataToEdit.moduleCode.trim(),
'moduleName': this.dataToEdit.moduleName.trim(),
'parentModule': this.dataToEdit.parentModule,
'parentModuleName': this.dataToEdit.parentModuleName,
'updateUser': this.dataService.loggedInUser
});
this.selectedParentModule = this.dataToEdit.parentModule;
alert('SElected Value:' + this.selectedParentModule);
});
} else {
this.mode = this.CREATE_MODE_INDICATOR;
this.dataCode = null;
this.dataToEdit = this.dummyData;
this.moduleListDisplayed = [...this.moduleList];
alert('Total:' + this.moduleList.length + ', Displayed:' + this.
moduleListDisplayed.length);
this.dataForm.setValue({
'moduleCode': this.dummyData.moduleCode,
'moduleName': this.dummyData.moduleName,
'parentModule': this.dummyData.parentModule,
'parentModuleName': this.dummyData.parentModuleName,
'updateUser': this.dataService.loggedInUser
});
}
});
});
}


Please help.

Regards,
Partha











-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to