I am trying to display data from an API's json result in my html using angular 5. I am unable to do i guess due to unnecessary 0 indexes in my json, kindly help. My json looks like -
{
"Plans": [
[{
"PlanId": 1,
"PlanName": "Free"
}, {
"PlanId": 2,
"PlanName": "Regular"
}, {
"PlanId": 3,
"PlanName": "Premium"
}]
],
"Location": [
[{
"States": [{
"StateId": 1,
"Country_Id": 1,
"StateName": "Alabama"
}, {
"StateId": 2,
"Country_Id": 1,
"StateName": "Alaska"
}, {
"StateId": 3,
"Country_Id": 1,
"StateName": "Arizona"
}, {
"StateId": 34,
"Country_Id": 1,
"StateName": "North Dakota"
}, {
"StateId": 50,
"Country_Id": 1,
"StateName": "Wyoming"
}],
"CountryId": 1,
"CountryName": "United States of America",
"CountryCode": "USA"
}, {
"States": [{
"StateId": 51,
"Country_Id": 2,
"StateName": "Alberta"
}, {
"StateId": 52,
"Country_Id": 2,
"StateName": "British Columbia"
}, {
"StateId": 53,
"Country_Id": 2,
"StateName": "Manitoba"
}, {
"StateId": 54,
"Country_Id": 2,
"StateName": "New Brunswick"
}, {
"StateId": 63,
"Country_Id": 2,
"StateName": "Yukon"
}],
"CountryId": 2,
"CountryName": "Canada",
"CountryCode": "CA"
}]
]
}
Image for 0 indexes I am talking about
I am trying to dynamically generate PlanNames i.e, Free, Regular,
<b>
<div class="col-md-4 text-center"*ngFor="let dummy of Plans" >
<div class="panel panel-pricing" >
<div class="panel-heading" >
<h3>{{dummy.PlanName}}</h3>
</div>
<div class="panel-body text-center">
<p><strong>$100 / Month</strong></p>
</div>
<div class="panel-footer">
<div class="radio">
<label><input type="radio" name="planradiogroup" id="planradio{{dummy.PlanId}}" [checked]="idx === 0" [value]="dummy.id" (change)="onSelectionChange(dummy)">Option {{dummy.PlanId}}</label>
</div>
</div>
</div>
</div>
</b>
My Component -
`
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
readonly apiTravelPlans = "http://localhost:50749/api/TravelGetDetails?type=json";
plans: any = typeof {};
constructor (private http:HttpClient){
this.ngOnInit().subscribe(data=>{
console.log(data);
this.plans = data;
});
}
posts: Observable<any>;
getPosts() {
this.posts = this.http.get(this.apiTravelPlans) //not used
}
ngOnInit(){
return this.posts = this.http.get(this.apiTravelPlans) // using to load json before my html
};
}
`