angular - ngOnInit not called on first request -


i facing weird issue in application.
whenever i'm routing 1 component ngoninit() not called due guess value countrieslist control not initialized. because when reload page pressing f5 ngoninit() called , value in countrieslist control rendered, facing issue single component, in rest of application ngoninit() called on every request. below code snippet:

import { component, oninit } '@angular/core'; import { router,activatedroute } '@angular/router'; import { formbuilder, formgroup, validators, formcontrol, reactiveformsmodule } '@angular/forms'; import { validator } "../shared/validators/validator"; import { authservice } 'angular2-social-login'; import { loginservice } '../login/login.service'; import { commonlogin } '../shared/commonservices/commonlogin.service'; import { userdata, storeuserdata } "../shared/commonservices/userdata.service";  @component({     selector: 'facebooklogin',     templateurl: './facebook-login.html',     providers: [loginservice, commonlogin,userdata,storeuserdata] }) export class facebooklogincomponent implements oninit {     ngoninit() {         debugger;   this.countrydetails();     }     socialform: formgroup;     formerror: any;     countrieslist: any;      constructor(private router: router, private activatedroute: activatedroute , private fb: formbuilder,         public _auth: authservice, private loginservice: loginservice, private commonlogin: commonlogin,         private userdata: userdata, private storeuserdata: storeuserdata) {         this.countrydetails();     }      countrydetails() {         this.commonlogin.countrydetails().subscribe(data => this.populatecountrylist(data), error => console.log(error));     }     populatecountrylist(data: any) {         var countriesdetails = json.parse(data._body).data.countries;         this.countrieslist = countriesdetails;     } 

below route call

this.router.navigate(['./facebooklogin']);   

please let me know wrong below code, have checked several options provided on this, this , other websites nothing worked

binding countrylist code:

<form class="loginform" id="socialform" [formgroup]="socialform" (ngsubmit)="registeruser(socialform.value)" #f="ngform"         novalidate>         <select class="form-control select" [formcontrol]="socialform.controls.country" [class.controlerror]="socialform.controls.country.haserror('required') && f.submitted">               <option *ngfor="let c of countrieslist" [ngvalue]="c">{{c.country_name}}</option>             </select>       </form> 


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -