我做错了什么?

import {bootstrap, Component} from 'angular2/angular2'

@Component({
  selector: 'conf-talks',
  template: `<div *ngFor="talk of talks">
     {{talk.title}} by {{talk.speaker}}
     <p>{{talk.description}}
   </div>`
})
class ConfTalks {
  talks = [ {title: 't1', speaker: 'Brian', description: 'talk 1'},
            {title: 't2', speaker: 'Julie', description: 'talk 2'}];
}
@Component({
  selector: 'my-app',
  directives: [ConfTalks],
  template: '<conf-talks></conf-talks>'
})
class App {}
bootstrap(App, [])

错误是

EXCEPTION: Template parse errors:
Can't bind to 'ngFor' since it isn't a known native property
("<div [ERROR ->]*ngFor="talk of talks">

推荐答案

我在talk门前错过了let分:

<div *ngFor="let talk of talks">

请注意,不推荐使用#...在NgFor等 struct 指令中声明局部变量.用let代替.

<div *ngFor="#talk of talks">现在变成了<div *ngFor="let talk of talks">

原始答案:

我在talk门前错过了#分:

<div *ngFor="#talk of talks">

It is so easy to forget that #. I wish the Angular exception error message would instead say:
you forgot that # again.

Typescript相关问答推荐

如何在TypScript中使参数类型化但可选

为什么TypScript对条件函数类型和仅具有条件返回类型的相同函数类型的处理方式不同?

React-Native运行方法通过监听另一个状态来更新一个状态

在配置对象上映射时,类型脚本不正确地推断函数参数

为什么从数组中删除一个值会删除打字错误?

在嵌套属性中使用Required

APIslice-CreateAPI的RTK打字错误

如何解决类型T不能用于索引类型{ A:typeof A; B:typeof B;. }'

如何使用类型谓词将类型限制为不可赋值的类型?

Angular 自定义验证控件未获得表单值

正交摄影机正在将渲染的场景切成两半

不带其他属性的精确函数返回类型

vue-tsc失败,错误引用项目可能无法禁用vue项目上的emit

无法将从服务器接收的JSON对象转换为所需的类型,因此可以分析数据

如何获取受类型脚本泛型约束的有效输入参数

我可以使用typeof来强制执行某些字符串吗

如何避免从引用<;字符串&>到引用<;字符串|未定义&>;的不安全赋值?

类型与泛型抽象类中的类型不可比较

类型脚本中参数为`T`和`t|unfined`的重载函数

如何使对象同时具有隐式和显式类型