简体   繁体   中英

how to show list in angular 2?

I am trying to show list in angular 2. I am getting template parsing error. I added this component

import {Component} from "@angular/core";
import {TodoService} from "./todo-service";
@Component({
    selector: 'todo-list',
    template: `<div>
        <ul>
          <li *ngFor="#t of todoService.todos">
            {{t}}
          </li>
         /ul>
       </div>`
})
export class TodoList {
  constructor(public todoService: TodoService) {}
}

try to display list. But getting this error

Error: Uncaught (in promise): Error: Template parse errors: Parser Error: Unexpected token # at column 7 in [ngFor #t of todoService.todos] in TodoList@2:21 ("

Here is my code http://plnkr.co/edit/FvdcxQoa5PCp0jx1tNgO?p=preview

Working Demo : http://plnkr.co/edit/tKMzJzlr0Zd6zSd5bHsX?p=preview

You just need to change # to let keyword.

<li *ngFor="let t of todoService.todos">

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