HTML Code:
- <select class="form-select style-1 selectbox" sb="48771331" style="display: none;" formControlName="AutoID">
- <option selected="0" value="0">---Select Country---option>
- <option *ngFor="let cd of countryData" value={{cd.AutoID}}>
- {{cd.Name}}
- option>
- select>
Component.ts:
- ngOnInit() {
- debugger;
- this.GetCountryList();
- }
- GetCountryList() {
- this.loading = true;
- this.schoolAddsService.GetCountryList()
- .subscribe(data => {
- this.loading = false;
- this.countryData=data;
- console.log(this.countryData);
- },
- error => {
- console.log("Error :: " + error);
- this.loading = false;
- }
- )
- }
Service.ts:
- export class SchoolAddsService{
- constructor(private http: Http) { }
- GetCountryList() {
- return this.http.get(environment.apiPath + 'Country/GetCountries')
- .map((res: Response) => res.json())
- .catch(this.handleError)
- }
- private handleError(error: Response) {
- return Observable.throw(error.statusText);
- }
- }

Replies
Know the answer? Post it — somebody with the same question will find it here.