Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i can't get json data in my model

What I have tried:

this is my app.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);
    });
 }
}


this is my service.ts

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');
    }

}


this is my 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" : [ ]
      } ]
    
     
    } ]
  }
}
Posted
Updated 18-Aug-18 5:15am
Comments
OriginalGriff 18-Aug-18 11:14am    
Repost: deleted.

1 solution

You already posted this qestion at I will get data from my nested json file with httpclient[^]. Please do not repost.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900