angular - Angular4 using a collection of object -


i working angular4 , don't know how declare collection of objects , adding item , removing item ? help

here did : component :

import { component } '@angular/core'; @component({   selector: 'app-root',   templateurl: './app.component.html',   styleurls: ['./app.component.css'] }) export class appcomponent {     // tableaux d'objets     personnes: object[]=[{id:1, nom: "alain"},{id: 2, nom: "clémentine"},{id: 3, nom: "cathy"}]; } 

the template :

<table>     <tr *ngfor="let personne of personnes">         <td>{{personne.id}}</td>         <td>{{personne.nom}}</td>     </tr> </table> 

it works fine, want manage collection of objects, instance user provide datas , i'll create new object datas , i'll add new object collection. tried this, doesn't work :

personnes: object[] = []; personne: = {{id:1, nom: "alain"}; this.personnes.push(this.personne); 

or

personnes: any[] = []; personne: = {{id:1, nom: "alain"}; this.personnes.push(this.personne); 

hi use array of , suggest check documentation in official site in https://www.typescriptlang.org/docs/handbook/basic-types.html , test using example http://embed.plnkr.co/vsqwitwk48bevwvciiai/


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -