简体   繁体   中英

Iterated names are not displaying using ngFor in angular2

I am new to Angular2. I wanted to display the list of items . In my first-angular-js-2-application.js file I have done as under

import {Component, View} from 'angular2/core';

@Component({
  selector: 'first-angular-js-2-application'
})

@View({
  templateUrl: 'first-angular-js-2-application.html'
})

export class FirstAngularJs2Application {

  constructor() {
    console.info('FirstAngularJs2Application Component Mounted Successfully');

     public products = [
                     {name: "Butter"},
                     {name: "Milk"},
                     {name: "Yogurt"},
                     {name: "Cheese"},
                  ];
  }
}

and in first-angular-js-2-application.html I have

<h1><b><font color="blue">Product names</font></b></h1>
<ul>
              <li *ngFor="#p of products" >
                  {{ p.name }}
              </li>
           </ul>

Now when I run the application, it is not displaying the product names.

What wrong I am making?

NB~ I have generated Angular2 application through Yoeman

try this

<li *ngFor="let p of products" >
                  {{ p.name }}
              </li>

I have created a plnkr but it is final version of angular2

Plunker Demo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM