2017-06-13 7 views
0

こんにちは私は、ドロップダウンリストに国名を表示しているときに問題に直面しています。データがタイプで取得されている間、私は私が正しく HTMLでTSをマッピングの問題にruningてと思うスクリプトここに私のTSコード角度2で動作しない選択タグにオブジェクトを表示する

export class SignupComponent{ 
registrationForm: FormGroup; 
username: AbstractControl; 
useremail: AbstractControl; 
countryCode: String = "JOR" ; 
viewCountryCode: String = "JOR"; 
languageCode: String; 
CountryId:number;  countries = CountryMapping.countryCode; 
submitAttempt: boolean = false; 
userResponse: UserResponse; 
apiResponseData: any; 
newCountries = []; 
urlCopied = true; 
    countryList: any =[]; 

constructor(public builder: FormBuilder, public homeService: HomeService, 
    private router: Router,private _http: Http, 
private loaderService: LoaderService, private helperService: 
HelperService, private translate: TranslateService) { 

this.languageCode = "EN" 
this.CountryId=96; 
this.homeService.getCountryByIp().subscribe(UserResponse => { 
    this.userResponse = UserResponse; 
    if (UserResponse.success) { 
    var cc = UserResponse.data.countryCode; 
     cc=cc.toLowerCase(); 
    this.viewCountryCode = cc; 
    } 
}); 
ngOnInit() { 

this.signUpDone = false; 
this.createSignupForm(); 
this.getCountryList(); 
this.getMerchantType(); 

} 

createSignupForm() { 
this.registrationForm = this.builder.group({ 
    username: ['', Validators.compose([ 
    Validators.required, 
    UserNameValidator.userNameRange, 
    UserNameValidator.OnlyAlphabets 
    ])], 
    useremail: ['', Validators.compose([ 
    Validators.required, 
    EmailValidator.mailFormat, 
    EmailValidator.domainCheckFormat, 
    EmailValidator.mailLength, 
    EmailValidator.specialCharacters 
    ])], 
    countryCode:[this.viewCountryCode], 
    commercialWebSiteLink: ['', Validators.compose([ 
    Validators.required, 
    UrlValidator.urlFormat, 
    ])], 

    corporateWebSiteLink: ['', Validators.compose([ 
    Validators.required, 
    UrlValidator.urlFormat, 
    ])], 
    merchantType: ['PSP'] 

}); 
this.username = this.registrationForm.controls['username']; 
this.useremail = this.registrationForm.controls['useremail']; 
this.commercialWebSiteLink = this.registrationForm.controls['commercialWebSiteLink']; 
this.corporateWebSiteLink = this.registrationForm.controls['corporateWebSiteLink']; 
this.regestrationErrorMessage = " "; 

    } 
    getCountryList() { 

this.homeService.getCountryList().subscribe(response => { 

    if (response.success) { 

    this.countryList = response.data; 
    console.log("retrieved the country list"); 
    } 

}); 
} 


<div class="form-group "> 
      <label class="control-label" for="countryCode">Country</label> 
      <select class="form-control" id="countryCode" formControlName="countryCode"> 
       <option *ngFor="let country of countryList" [ngValue]="country" [attr.value]="country.countryCode" [selected]="country.countryName == viewCountryCode"> 
        {{country.countryName}}</option> 
      </select> 
     </div> 

がある、私は本当に助けてください、私は本当にこれが明日で動作させるために必要な任意の助けをいただければ幸いです私

+0

'getCountryList()'の結果オブジェクトの例がありますか? – Catalyst

+0

それはあなた自身が応答を意味するのですか?今は国のリストを記録しようとしたときに0オブジェクトが返ってきました。それから国を記録しようとしました。そして次のようなオブジェクトを返しました: jp:Object countryCode: "JPN" countryName: "日本(日本)" dialCode: "+ 81" __proto __:Object –

+0

私たちのためにHTMLも投稿できますか?あなたが走っている '* ngFor'の問題かもしれません。 –

答えて

0

これはバックエンド(春)の国リストでは見えない面白い質問が間違っていたデータを取得していたしたがって、ドロップダウンリストで国が生成されず、検索されました。上記のコードでは問題はありませんでした。

関連する問題