2017-06-13 45 views
0

你好我相信新的角我面臨的一個問題,而在下降downlist顯示國名,下落而數據在類型檢索向下沒有顯示任何選項劇本我想我乳寧與HTML正確 這裏映射TS的問題是我的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:對象 COUNTRYCODE: 「JPN」 國家名稱: 「日本(日本)」 dialCode: 「+ 81」 __proto __:對象 –

+0

你可以發佈爲我們的HTML以及。我相信這可能是你正在運行的'* ngFor'的一個問題。 –

回答

0

這是有趣的,似乎在後端(春季)任何國家列表的查詢,這是錯誤被檢索沒有數據因此在下拉列表中沒有生成任何國家/地區,被檢索到,上面的代碼沒有問題,就像魅力一樣。