Click here to Skip to main content
15,890,185 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a Httpclient app and i wana get data from json list but does'nt work

What I have tried:

<pre>"this is my app.component.ts"


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 MyData {
data : {
    altMenuListe: Object[]
}
}
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
   records: [];
  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.altMenuListe;
    });
 }
}



"and this is my service.ts"

import { Injectable } from '@angular/core';
import { HttpClient  } from '@angular/common/http';

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

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

}


"and this is my json list"

{
  "okundu" : "okunmadi",
  "degisti" : "",
  "successful" : true,
  "messageCode" : null,
  "messageText" : null,
  "total" : null,
  "data" : {
    "okundu" : "okunmadi",
    "degisti" : "",
    "menuId" : null,
    "ustMenuId" : null,
    "projeFormId" : null,
    "menuSira" : null,
    "menuKod" : null,
    "menuAd" : "I-DEAL Menü",
    "menuSimge" : null,
    "menudeTiklan" : null,
    "menuFavori" : null,
    "isLeaf" : null,
    "leaf" : null,
    "versionId" : null,
    "icon" : null,
    "altMenuListe" : [ {
      "okundu" : "okunmadi",
      "degisti" : "",
      "menuId" : 2,
      "ustMenuId" : 0,
      "projeFormId" : null,
      "menuSira" : 11,
      "menuKod" : null,
      "menuAd" : "Sistem Yönetimi",
      "menuSimge" : "fa-cogs",
      "menudeTiklan" : false,
      "menuFavori" : false,
      "isLeaf" : false,
      "leaf" : 0,
      "versionId" : 49,
      "icon" : "http://192.168.12.10:8088/dealResources/images/simge/16x16/klasor.jpg",
      "altMenuListe" : [ {
        "okundu" : "okunmadi",
        "degisti" : "",
        "menuId" : 15,
        "ustMenuId" : 2,
        "projeFormId" : 1,
        "menuSira" : 1,
        "menuKod" : "sistem.bilgisayar.BilgisayarView",
        "menuAd" : "Bilgisayar Kayıtları",
        "menuSimge" : null,
        "menudeTiklan" : true,
        "menuFavori" : false,
        "isLeaf" : true,
        "leaf" : 1,
        "versionId" : 38,
        "icon" : "http://192.168.12.10:8088/dealResources/images/simge/16x16/form.jpg",
        "altMenuListe" : [ ]
      }, {
        "okundu" : "okunmadi",
        "degisti" : "",
        "menuId" : 55,
        "ustMenuId" : 2,
        "projeFormId" : 36,
        "menuSira" : 2,
        "menuKod" : "sistem.guncelle.SistemGuncelleForm",
        "menuAd" : "Sistem Güncelle",
        "menuSimge" : null,
        "menudeTiklan" : true,
        "menuFavori" : false,
        "isLeaf" : true,
        "leaf" : 1,
        "versionId" : 41,
        "icon" : "http://192.168.12.10:8088/dealResources/images/simge/16x16/form.jpg",
        "altMenuListe" : [ ]
      }, {
        "okundu" : "okunmadi",
        "degisti" : "",
        "menuId" : 209,
        "ustMenuId" : 2,
        "projeFormId" : 147,
        "menuSira" : 3,
        "menuKod" : "sistem.yonetim.ProjeAyarlari",
        "menuAd" : "Proje Parametre Ayarları",
        "menuSimge" : null,
        "menudeTiklan" : true,
        "menuFavori" : false,
        "isLeaf" : true,
        "leaf" : 1,
        "versionId" : 43,
        "icon" : "http://192.168.12.10:8088/dealResources/images/simge/16x16/form.jpg",
        "altMenuListe" : [ ]
      }, {
        "okundu" : "okunmadi",
        "degisti" : "",
        "menuId" : 33,
        "ustMenuId" : 2,
        "projeFormId" : 3,
        "menuSira" : 4,
        "menuKod" : "sistem.bolge.BolgeView",
        "menuAd" : "Bölge Tanımları",
        "menuSimge" : null,
        "menudeTiklan" : true,
        "menuFavori" : false,
        "isLeaf" : true,
        "leaf" : 1,
        "versionId" : 46,
        "icon" : "http://192.168.12.10:8088/dealResources/images/simge/16x16/form.jpg",
        "altMenuListe" : [ ]
      }, {
        "okundu" : "okunmadi",
        "degisti" : "",
        "menuId" : 43,
        "ustMenuId" : 2,
        "projeFormId" : 26,
        "menuSira" : 5,
        "menuKod" : "sistem.menukayit.MenuKayitTree",
        "menuAd" : "Ağaç Menu Düzenleme",
        "menuSimge" : null,
        "menudeTiklan" : true,
        "menuFavori" : false,
        "isLeaf" : true,
        "leaf" : 1,
        "versionId" : 46,
        "icon" : "http://192.168.12.10:8088/dealResources/images/simge/16x16/form.jpg",
        "altMenuListe" : [ ]
      }, {
        "okundu" : "okunmadi",
        "degisti" : "",
        "menuId" : 51,
        "ustMenuId" : 2,
        "projeFormId" : 32,
        "menuSira" : 6,
        "menuKod" : "sistem.kullaniciyetki.KullaniciYetkiView",
        "menuAd" : "Kullanıcı Yetki Tanımları",
        "menuSimge" : null,
        "menudeTiklan" : true,
        "menuFavori" : false,
        "isLeaf" : true,
        "leaf" : 1,
        "versionId" : 45,
        "icon" : "http://192.168.12.10:8088/dealResources/images/simge/16x16/form.jpg",
        "altMenuListe" : [ ]
      }, {
        "okundu" : "okunmadi",
        "degisti" : "",
        "menuId" : 59,
        "ustMenuId" : 2,
        "projeFormId" : 38,
        "menuSira" : 7,
        "menuKod" : "sistem.menukayit.MenuKayitView",
        "menuAd" : "Sistem Form Tanımları",
        "menuSimge" : null,
        "menudeTiklan" : true,
        "menuFavori" : false,
        "isLeaf" : true,
        "leaf" : 1,
        "versionId" : 43,
        "icon" : "http://192.168.12.10:8088/dealResources/images/simge/16x16/form.jpg",
        "altMenuListe" : [ ]
      }, {
        "okundu" : "okunmadi",
        "degisti" : "",
        "menuId" : 862,
        "ustMenuId" : 2,
        "projeFormId" : 56,
        "menuSira" : 8,
        "menuKod" : "stok.stokRecete.StokReceteView",
        "menuAd" : "Stok Reçete Tanımları",
        "menuSimge" : null,
        "menudeTiklan" : true,
        "menuFavori" : false,
        "isLeaf" : true,
        "leaf" : 1,
        "versionId" : 39,
        "icon" : "http://192.168.12.10:8088/dealResources/images/simge/16x16/form.jpg",
        "altMenuListe" : [ ]
      }
}]
}]
}


"But i can't get data from link my records variable is empty"
Posted
Updated 18-Aug-18 3:25am
v2
Comments
OriginalGriff 18-Aug-18 4:41am    
And?
What's the problem?
Any error message? What are they? When do you get them? What do you do to get them?
What have you tried to find out why? What did the debugger show?
Where are you stuck?
What help do you need?
Hassan Bahmani 18-Aug-18 4:54am    
i no have error just i can't get compeletly data from my list
OriginalGriff 18-Aug-18 5:05am    
OK - so move on to the next set of questions:
"What have you tried to find out why? What did the debugger show?
Where are you stuck?
What help do you need?"
Hassan Bahmani 18-Aug-18 5:07am    
app doesn't stuk just doesn't get me data from my json list i think my export interface has problem
Hassan Bahmani 18-Aug-18 5:08am    
in debugger my altMenuListe var is empty

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