1

I had add popup field, when the popup opens i want to get one field to be preselected with its option, i am getting the required value in console but its not reflecting on html. Can anyone help me to solve this issue.

HTML:

<div class="form-group">
  <label class="showlabel">Role</label>
   {{selectedRole}}
  <ng-select [options]="roles" [(ngModel)]="user.user.role_id" name="AddRole" class='filterDropDown cat' placeholder="Role" notFoundMsg="No Role Found" required> 
  </ng-select>
</div>

TS: To open popup

addCompany (){ 
  this.user = new Users(); 
  this.addCompanies.show();
  let userData = this.roles.filter(role => role.label === 'appUser');
  if(userData && userData[0]) { 
    this.selectedRole = userData[0].label.toString();
  }
  console.log(this.selectedRole);
}
Bhrungarajni
  • 2,415
  • 11
  • 44
  • 88

1 Answers1

1
class MyComponent implements OnInit {
  ngOnInit() {
    // set the value of dropdown which u want to select
  }
}

when your component load it it will run both ngOninit and constructor so you can set the preselect value any one place.

if you want with example i need data.

Arun
  • 450
  • 3
  • 8