Elior Sastiel Elior Sastiel - 1 year ago 95
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!

Answer Source

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}}

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download