Elior Sastiel Elior Sastiel - 3 months ago 7x
AngularJS Question

ngFor problam- Angular2

I just started to learn Angular2, and I got a problem with ngfor.
This is my code:

import { Component } from '@angular/core';
import {Person} from "./Person";

selector: 'my-app',
moduleId: module.id,
templateUrl: 'app.component.html'

export class AppComponent {
public title = 'Telphone-books';
public persons=PERSONS;

const PERSONS: Person[] = [
{id:1, Name:'Shai', LastName:'Sastiel', Telphone: '999999'},
{id:2, Name:'Jon', LastName:'ali', Telphone: '888888'},
{id:3, Name:'zeav', LastName:'jobs', Telphone: '7777777'},
{id:4, Name:'byson', LastName:'ffaf', Telphone: '6666666'}


This is my app.component.html:

<li *ngFor="let person of PERSONS">

when I run this code I see only the title, but i dont see the arrays of persons.
did i write the ngfor right? maybe i miss somethins?
Thanks for any help!


Binding expressions can only refer to members of the component instance but not arbitrary global stuff.

You need to refer the property of your component instance instead of the global variable:

  <li *ngFor="let person of persons">

as mentioned by @rinukkusu {{persons.Name}} should be {{person.Name}}