0

Hi guys I'm working on Angular application and I would like some help to fetch the data from the json. I've got my conpoments.ts with my method but it is not working. I included the json file. please help me to display the data on html page.Thank you

label: "car"
manufacture:Array(3)
{id: "1", label: "name", question: "", type: "type", value: {…}}
{id: "2", label: "name", question: "", type: "type", value: {…}}
{id: "3", label: "name", question: "", type: "type", value: {…}}


import { Component, OnInit } from '@angular/core';

import { ManufactureService } from '../../services/ManufactureService/manufacture.service';


@Component({
  selector: 'body-content',
  templateUrl: './body.component.html',
  styleUrls: ['./body.component.less']
})
export class BodyComponent implements OnInit {
  constructor(public 
  manufactureService:ManufactureService) { }
  async ngOnInit() {

  const [err,data] = await  this. manufactureService.getManufature('car','man').toPromise()

   if (err) {
        console.log(err)
        return false
    } 

    showCar(data){
    data.forEach(el=>{
      this.manufactureService.getManufature.push();
    })
  }

  }
}
0

1 Answer 1

0

Try This :

import HttpClientModule in app.module.ts

export class MyComponent implements OnInit {

  constructor(private manufactureService: ManufactureService) {}

  ngOnInit(): void {
    this. manufactureService.getManufature(subscribe(data => {
      console.log("results :", data)
      data.forEach(el=>{
        this.manufactureService.getManufature.push();
    })
    },error => {
      console.log("Error :", error)
    });
  }
}

Service Function :

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

constructor(private http: HttpClient) {} 

getManufature(){
    return this.http.get('path or url to JSON'); 
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.