我正在尝试按照教程进行操作。这是一个显示课程的简单页面。我在控制台中遇到错误。 Angular 2依赖是" angular2":" 2.0.0-beta.7"。我尝试过使用'#'而不是'让'。
无法绑定到' ngFor'因为它不是一个已知的本地财产 (" {{标题}} ] * ngFor ="课程课程"> {{课程}}
模块course.components.ts
import {Component} from 'angular2/core';
import {CoursesService} from './courses.service';
@Component({ selector:'courses',
template:`<h1>Courses</h1>
{{title}}
<ul>
<li *ngFor="let course for courses">
{{course}}
</li>
</ul>
`,
providers:[CoursesService]
})
export class CoursesComponent
{
title="The title of courses page";
courses;
constructor(coursesService:CoursesService)
{
this.courses = coursesService.getCourses();
}
}
Module course.service.ts
export class CoursesService
{
getCourses():string[]
{
return ["Course1","Course2","Course3"];
}
}
答案 0 :(得分:1)
你在课程前错过了for
:
<li *ngFor="let course of courses">
并正确导入您的服务文件。
我也在http://plnkr.co/edit/ldpRkJLR89e6aF4McdQD?p=preview
为您创建了一个plunker希望这有帮助!
答案 1 :(得分:0)
Angular 2在几个星期前发布了最终版本,您应该更新到最终版本以捕获更改并注意到在2.0.0.beta.7中#
尚未弃用