I am messing around with this right now too :-)

Try
value={{name}}

<input
       id="my-name"
       autofocus
       #newname
       (keyup)="changeName($event, newname)"
       >


Just found out camelCase for variable names is a bad idea
#newName did not make it to my function. (maybe gets converted to new-name)

On 9 March 2015 at 15:44, Martin Kuhn <[email protected]> wrote:

> I'm curious about two way databinding in Angular2.
>
> I played around with the quickstart project and would like to know how to
> get a value from an UI-element back to the model:
>
> In the source example I used the change event and a manually update of the
> model.
>
> But this may not be the right way, or???
>
> Here the example:
>
>  import {Component, Template, bootstrap} from 'angular2/angular2';
>
>
> @Component({
>     selector: 'my-app'
> })
>
> @Template({
>     inline:
>         '<h1>Hello {{ name }}</h1><br/>' +
>         '<button (click)="changeValue()">Change</button>' +
>         '<input #input type="text" name="user" [value]="name" 
> (change)="update($event)">'
> })
>
> // Component controller
> class MyAppComponent {
>     constructor() {
>         this.name = 'Alice';
>     }
>
>     changeValue() {
>         this.name='Peter';
>     }
>
>     update(e) {
>         console.log('update',e.srcElement.value);
>         this.name=e.srcElement.value;
>     }
> }
>
>
> bootstrap(MyAppComponent);
>
>  --
> You received this message because you are subscribed to the Google Groups
> "AngularJS" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/angular.
> For more options, visit https://groups.google.com/d/optout.
>



-- 

*AJ Mercer*
<webonix:net strength="Industrial" /> <http://webonix.net> | <webonix:org
community="Open" /> <http://webonix.org>
http://twitter.com/webonix

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to