Я использую этот плагин в своем проекте.Я получаю всю свою страну от веб-службы, API с этой функцией:
Service.ts
public getAllCountry(): Observable<Country[]> {
return this.http.get(Api.getUrl(Api.URLS.countryGetAll), {
})
.pipe(map((response: Response) => {
let res = response.json();
if (res.StatusCode === 1) {
this.auth.logout();
} else if (res.StatusCode === 4) {
return false;
} else if (res.StatusDescription === 'No result') {
return false;
} else if (res.StatusDescription === '[]') {
return false;
} else if (res.StatusDescription === []) {
return false;
} else {
return res.StatusDescription.map(country => {
return new Country(country);
});
}
},
(error) => {
console.log(error);
}))
}
Вызов из службы getAllCountry();
в component.ts Component.ts
public country: Country[] = [];
@ViewChild("autocomplete") autocomplete: RadAutoCompleteTextViewComponent;
ngOnInit(): void {
this.getallcountry();
}
getallcountry() {
this.ws.getAllCountry().subscribe(
country => {
this.country = country;
console.log('country',country)
},
err => console.error('err', err),
() => console.log('error')
);
}
Показать этот результат:
JS: country [{
JS: "name": "Afghanistan",
JS: "short_name": "AF",
JS: "country_id": 1
JS: }, {
JS: "name": "Albania",
JS: "short_name": "AL",
JS: "country_id": 2
JS: }, {
JS: "name": "Algeria",
JS: "short_name": "DZ",
JS: "country_id": 3
JS: }, {
JS: "name": "American Samoa",
JS: "short_name": "AS",
JS: "country_id": 4
JS: }, {
JS: "name": "Andorra",
JS: "short_name": "AD",
JS: "country_id": 5
JS: },{
JS: "...}]
В html я пишу этот код:
<Label text="Select country"></Label>
<RadAutoCompleteTextView #autocomplete [items]="country" suggestMode="Suggest" displayMode="Tokens">
<SuggestionView tkAutoCompleteSuggestionView>
<ng-template tkSuggestionItemTemplate let-item="item">
<StackLayout orientation="vertical" padding="10">
<Label [text]="item.name"></Label>
</StackLayout>
</ng-template>
</SuggestionView>
</RadAutoCompleteTextView>
В поле зрения не отображается ни одна страна.
Можете ли вы подсказать мне, как работать с этим плагином, когда я вызываю страну из API?
Спасибо!