TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Saravanan Np
NA
171
35.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
constructor(
private
httpService: HttpClient){}
myInsuredTypes: string[];
selected =
null
;
ngOnInit () {
this
.httpService.get(
'http://192.168.1.51/masterapi/api/GetInsurance'
).subscribe(
data => {
this
.myInsuredTypes = data as string [];
// FILL THE ARRAY WITH DATA.
},
(err: HttpErrorResponse) => {
console.log (err.message);
}
);
}
App.component.html
<div style=
"float:left;padding:10px;margin:0 auto;"
>
<select [(ngModel)]=
"selected"
>
<option [(ngValue)]=
"description"
>{{description}}</option>
</select>
<p>{{ selected }}</p>
</div>
App.module.ts
// API Section
import
{ HttpClientModule } from
'@angular/common/http'
;
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.
Reply
Answers (
5
)
when and how to use interceptor?
How to set download path in Angular 2