Hassan Bahmani Ответов: 1

Я вам данные из вложенных JSON-файл с помощью HttpClient


я не могу получить данные json в своей модели

Что я уже пробовал:

это мое приложение.component.ts


<pre>import { Component, OnInit  } from '@angular/core';
import { RecordsService } from './records.service';
// tslint:disable-next-line:import-blacklist
import { map } from 'rxjs/operators';
import {Observable} from 'rxjs';
import { ArrayType } from '@angular/compiler';
// tslint:disable-next-line:prefer-const

export interface RootObject {
  data: Data;
}

 export interface Data {
  altMenuListe: AltMenuListe2[];
}

export interface AltMenuListe2 {
  ustMenuId: number;
  menuAd: string;
  isLeaf: boolean;
  leaf: number;
  altMenuListe: AltMenuListe[];
}

export interface AltMenuListe {
  ustMenuId: number;
  menuAd: string;
  isLeaf: boolean;
  leaf: number;
  altMenuListe: any[];
}
  @Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
   records: any;
  title = 'Angular Rest Api Test';
  // tslint:disable-next-line:use-life-cycle-interface
  constructor(private myFirstService: RecordsService) {
  }
  // tslint:disable-next-line:use-life-cycle-interface
  ngOnInit() {
     this.myFirstService.getData()
     .subscribe(dataS => {
      this.records = dataS.data;
      console.log(this.records);
    });
 }
}


это моя служба.

import { Injectable } from '@angular/core';
import { HttpClient  } from '@angular/common/http';
import { Data } from './app.component';
import { AltMenuListe2 } from './app.component';
import { AltMenuListe } from './app.component';

import { RootObject } from './app.component';
@Injectable()
export class RecordsService {

  constructor(private http: HttpClient) {}
      getData() {
        return  this.http.get
        <RootObject>
        ('http://192.168.12.10:8088/sistemApi/menuGetir?_dc=1534489724075');
    }

}


это мой json

{
  "data" : {
   
    "altMenuListe" : [ {
             "ustMenuId" : 2,
        "menuAd" : "Birim Kapat",
        "isLeaf" : true,
        "leaf" : 1,
        
      "altMenuListe" : [ {
               "ustMenuId" : 2,
        "menuAd" : "Birim Kapat",
        "isLeaf" : true,
        "leaf" : 1,
        "altMenuListe" : [ ]
      }, {
              "ustMenuId" : 2,
        "menuAd" : "Birim Kapat",
        "isLeaf" : true,
        "leaf" : 1,
        "altMenuListe" : [ ]
      }, {
             "ustMenuId" : 2,
        "menuAd" : "Birim Kapat",
        "isLeaf" : true,
        "leaf" : 1,
        "altMenuListe" : [ ]
      }, {
               "ustMenuId" : 2,
        "menuAd" : "Birim Kapat",
        "isLeaf" : true,
        "leaf" : 1,
        "altMenuListe" : [ ]
      }, {
             "ustMenuId" : 2,
        "menuAd" : "Birim Kapat",
        "isLeaf" : true,
        "leaf" : 1,
        "altMenuListe" : [ ]
      }, {
              "ustMenuId" : 2,
        "menuAd" : "Birim Kapat",
        "isLeaf" : true,
        "leaf" : 1,
        "altMenuListe" : [ ]
      }, {
             "ustMenuId" : 2,
        "menuAd" : "Birim Kapat",
        "isLeaf" : true,
        "leaf" : 1,
        "altMenuListe" : [ ]
      }, {
           "ustMenuId" : 2,
        "menuAd" : "Birim Kapat",
        "isLeaf" : true,
        "leaf" : 1,
        "altMenuListe" : [ ]
      }, {
               "ustMenuId" : 2,
        "menuAd" : "Birim Kapat",
        "isLeaf" : true,
        "leaf" : 1,
        "altMenuListe" : [ ]
      }, {
               "ustMenuId" : 2,
        "menuAd" : "Birim Kapat",
        "isLeaf" : true,
        "leaf" : 1,
        "altMenuListe" : [ ]
      }, {
             "ustMenuId" : 2,
        "menuAd" : "Birim Kapat",
        "isLeaf" : true,
        "leaf" : 1,
        "altMenuListe" : [ ]
      }, {
                "ustMenuId" : 2,
        "menuAd" : "Birim Kapat",
        "isLeaf" : true,
        "leaf" : 1,
        "altMenuListe" : [ ]
      }, {
                "ustMenuId" : 2,
        "menuAd" : "Birim Kapat",
        "isLeaf" : true,
        "leaf" : 1,
        "altMenuListe" : [ ]
      }, {
        "ustMenuId" : 2,
        "menuAd" : "Birim Kapat",
        "isLeaf" : true,
        "leaf" : 1,
        "altMenuListe" : [ ]
      }, {
              "ustMenuId" : 2,
        "menuAd" : "Birim Kapat",
        "isLeaf" : true,
        "leaf" : 1,
        "altMenuListe" : [ ]
      }, {
        "ustMenuId" : 2,
        "menuAd" : "Birim Kapat",
        "isLeaf" : true,
        "leaf" : 1,
        "altMenuListe" : [ ]
      } ]
    
     
    } ]
  }
}

OriginalGriff

Репост: удален.

1 Ответов

Рейтинг:
0

Richard MacCutchan

Вы уже разместили этот вопрос на сайте Я вам данные из вложенных JSON-файл с помощью HttpClient[^Пожалуйста, не делайте репостов.