0

jsonArray を angular の文字列に変換してから、html で選択 (ドロップダウン ピッカー) として表示したいと考えています。

JSON URL は次のようになります。

[
    "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);
    }
 }

store.component.ts と app.component ファイルにサービスをインポートしました

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>

私が知る限り、私の getcontentFromApi メソッドは正しくなく、html select へのバインドが機能していません。

4

0 に答える 0