I have the code for drop down it can't be display when page is loaded. The drop down is display once clicked refresh button.
html:
<div class="form-group row">
<select id="select111" name="role" placeholder="Roles" class="form-control selectpicker" style="width:476px;">
<option *ngFor="let role of roles" [value]="role">{{role}}</option>
</select>
</div>
component.ts:
export class RegistrationComponent implements OnInit {
submitted = false;
loading= false;
// registrationForm: FormGroup;
roles = ['User', 'Admin' ,'Supervisor'];
registers={
username:'',
email:'',
password:'',
companyName:'',
role:''
}
registervalid=false;
constructor(private authService: AuthService,public router:Router,public http:Http) {
}
ngOnInit(): void {
this.registers.role=this.roles[0];
}
onDefault($event){
$event.preventDefault();
console.log('selected: ' + $event.target.value);
}
CreateAccount(){
this.submitted = true;
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
let body = JSON.stringify(this.registers);
console.log('the registers is a' + body)
this.http.post('http://localhost:3000/api/user', body,options).map((res:Response) => res.json())
.subscribe( data =>{
this.registers = data;
console.log(' data object' +JSON.stringify(data));
if (data) {
console.log('insert sucess msg' +JSON.stringify(this.registers));
alert('login is successfully');
this.router.navigate(['/login ']);
}
},
err => console.error(err),
() => console.log('done')
);
}
}
`I used the angular2 here no controller all are components, In this file i wrote registration page for my application'.
The filed i added the drop for register person is enter with type as User or Admin or Supervisor, here i that drop down fields is not display when the registration page is loaded, it's show when we refresh already loaded page once again.
i attach the output images as follows: here the dropdown is not dsiplay after the companyName filed
And after i reload the page the dropdown is display (i.e) follows: the dropdown is comes after readload