1

Im trying to populate an angular table with data received from a restapi database but i cannot get it to populate at all. I can send the data to the console with console.log but i need to populate a table which i am unsure of how to do, any help is appreciated.

partycomponent.html

<tr *ngFor="let parties of partyArray">
    <td>{{PARTY.MNEMONIC}}</td>
    <td>{{PARTYNAME}}</td>
    <td>{{PARTYCOLOUR}}</td>
 </tr>

parties.component.ts

 parties = [];
  constructor(httpClient: HttpClient) { 
    httpClient.get('http://localhost:3000/parties')
    .subscribe(obj => {
      console.log(obj);
      this.parties = obj as any[];
    })
  }

I can put the data into the console from the sql link above but cannot put it on screen inside the table I have made.

My sql works correctly and the link is correct as i can post the data to the console but just cannot seem to get it posting on screen. Any help is appreciated

1 Answer 1

1
<tr *ngFor="let party of parties">
    <td>{{party.PARTY_MNEMONIC}}</td>
    <td>{{party.PARTYNAME}}</td>
    <td>{{party.PARTYCOLOUR}}</td>
 </tr>

You are binding it wrongly.

Sign up to request clarification or add additional context in comments.

5 Comments

Ive made the changes but It is still not populating the table, is the let parties of partyArray correct im new to this language so im unsure
post here the response you received.
0: {PARTY_MNEMONIC: "AON", PARTYNAME: "Aontú", PARTYCOLOUR: "4650b9"} 1: {PARTY_MNEMONIC: "FF", PARTYNAME: "Fianna Fáil", PARTYCOLOUR: "14aa55"} 2: {PARTY_MNEMONIC: "FG", PARTYNAME: "Fine Gael", PARTYCOLOUR: "00a0e1"} 3: {PARTY_MNEMONIC: "GP", PARTYNAME: "Green Party", PARTYCOLOUR: "91b905"} 4: {PARTY_MNEMONIC: "IND", PARTYNAME: "Independent", PARTYCOLOUR: "dc9b14"} 5: {PARTY_MNEMONIC: "LAB", PARTYNAME: "Labour", PARTYCOLOUR: "d7323c"}
i receive that in the console but its not populating within the table, the sql works but im messing something up to fill the table just

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.