0

Basically what i have done is to insert some data to the database via the python server- werkzeug. and another function to retreive those data from database. everything works fine with the result shown in the console of the browser. now how to print those result which is in json format in a html table. my code is very simple it does not contain any ngAapp or ngController.

import { Component } from '@angular/core';
import {Http, Response, Headers} from '@angular/http';

@Component({
    selector: 'app-meta',
    templateUrl: './meta.component.html',
    styleUrls: ['./meta.component.css']
})
export class MetaComponent  {
    res: any[];
    json;

    constructor(private http: Http) {}

    public getall(){
    // alert('error');
        const data = {
            "jsonrpc" : "2.0",
            "method" : "getall",
            "id" : "1",
            "params": {'argument' : 'something' }
        };
        this.http.post('http://localhost:80/jsonrpc', data).subscribe( res => console.log(this.json =   
res.text()));
        // ...

HTML:

<button (click)="getall()">view</button>
<pre>{{json}}</pre>

the response i got in my html page after clicking the button is :

{"result": [["water", "None"], ["temp", "001"], ["temp", "002"], ["temp", "003"], ["temp", "004"], ["temp", "005"], ["temp", "006"], "id": "1", "jsonrpc": "2.0"}

How to display this data in a table in the html page?

6
  • w3schools.com/js/tryit.asp?filename=tryjson_html_table Commented Mar 6, 2020 at 7:49
  • Hi @DaanSeuntjens i'm new to angular,can you be more specific where to implement this? Commented Mar 6, 2020 at 7:58
  • I'm actually not familiar with angularjs as well, but try to search online how you could tackle these problems. F.e. search for "angularjs json parsing" or "angularjs json tutorial example" or such and you'll probably find what you are looking for Commented Mar 6, 2020 at 8:04
  • Your json format is not valid. Could you please check once? Commented Mar 6, 2020 at 10:15
  • check this stackoverflow.com/questions/5180382/… Commented Mar 6, 2020 at 10:15

1 Answer 1

1
<tr *ngFor="let i of json" >
      <td>
        <input type=text [(ngModel)]="i.result" >
     </td>
</tr>

This will loop ur json data in table and u should alter the looping data as u need cheers..!

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.