2

I am trying to build a little app with Angular2. I want to use local variables, like it is explained here:

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

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

But it doesn't work as expected. If i press a key on the focused input field, the text in the p-tag should be updated. But all i get is an Exception:

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

If i do something like this it will work, even if the foo method exists or not:

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

I followed exactly the instructions on the page and i don't have any custom code.

2
  • I think it's bug, create this issue Commented Oct 8, 2015 at 18:02
  • 3
    when you use the (event) notation you must provide the function to be called .. The examples in the angular.io site are not up to date ( they use 2.0.0-alpha.37 .. the current version is alpha39 ) Commented Oct 8, 2015 at 20:05

1 Answer 1

2

It looks like the docs have been updated:

<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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.