Saravanan Np

Saravanan Np

  • NA
  • 171
  • 33.9k

get api from dropdown values

Mar 13 2019 2:08 AM
How to get dropdown values through from angular api??
 
below shared my code, could u guys help me please
 
App.Component.ts
  1. constructor(private httpService: HttpClient){}  
  2. myInsuredTypes: string[];  
  3. selected = null;  
  4.   
  5. ngOnInit () {  
  6. this.httpService.get('http://192.168.1.51/masterapi/api/GetInsurance').subscribe(  
  7. data => {  
  8. this.myInsuredTypes = data as string []; // FILL THE ARRAY WITH DATA.  
  9. },  
  10. (err: HttpErrorResponse) => {  
  11. console.log (err.message);  
  12. }  
  13. );  
  14. }  
App.component.html
  1. <div style="float:left;padding:10px;margin:0 auto;">  
  2. <select [(ngModel)]="selected">  
  3. <option [(ngValue)]="description">{{description}}</option>  
  4. </select>  
  5.   
  6. <p>{{ selected }}</p>  
  7. </div>  
App.module.ts
  1. // API Section  
  2. import { HttpClientModule } from '@angular/common/http';  
  3. import { FormsModule } from '@angular/forms';  
Errors comes
 
Access to XMLHttpRequest at 'http://192.168.1.51/masterapi/api/GetInsurance/' from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Answers (5)