I want to convert the jsonArray to a string in angular then show it as a select (dropdown picker) in html.
The JSON Url looks like this:
[
"100 - BISCUIT - 546156",
"252 - CHOCO - 185268",
"131 - CANDY - 478215"
]
my.service.ts:
import { Injectable } from '@angular/core';
import { Http, Response, Headers, RequestOptions } from '@angular/http';
import { Observable } from 'rxjs';
@Injectable()
export class MyService {
//Json Url
private jsonUrl = 'localhost:8080/jsonurl';
constructor(private http: Http) {
}
public getContentFromApi() {
return this.http.get(this.jsonUrl);
}
}
I have imported service in store.component.ts and in app.component file
import { Component, OnInit } from '@angular/core';
import { MyService } from '../../services/my.service'
@Component({
selector: 'app-store',
templateUrl: './store.component.html',
styleUrls: ['./store.component.css'],
providers: [MyService]
})
export class StoreComponent implements OnInit {
selectedValue: any;
storeItems: any;
si: myService;
constructor(){ }
ngOnInit() {
this.storeItems = this.si.getContentFromApi;
}
getStoreItems() {
return this.storeItems;
}
}
store.component.html
<div class="alignment">
<p class="lev">Store Items:
<select [(ngModel)]="selectedValue"><option *ngFor="let s of storeitems" [ngValue]="s">{{storeitems}}</option></select></p>
</div>
As far as I can tell, my getcontentFromApi method is not right, and the binding to html select is not working.