Angular2 with Typescript 带有局部变量的简单示例

Angular2 with Typescript simple example with local variables

我正在尝试使用 Angular2 构建一个小应用程序。我想使用局部变量,就像这里解释的那样:

https://angular.io/docs/ts/latest/guide/user-input.html

<input #myname (keyup)>
<p>{{myname.value}}</p>

但它没有按预期工作。如果我在聚焦的输入字段上按下一个键,p-tag 中的文本应该被更新。但我得到的只是一个例外:

EXCEPTION: TypeError: rec[(rec.length - 1)] is undefined

如果我这样做它会起作用,即使 foo 方法存在与否:

<input #myname (keyup)="foo()">
<p>{{myname.value}}</p>

我完全按照页面上的说明操作,没有任何自定义代码。

好像the docs已经更新了:

<input #box (keyup)="0">

... an Event Binding requires a template expression to evaluate when the event fires. Many things qualify as expressions, none simpler than a one-character literal like the number zero. That's all it takes to keep Angular happy.