What I mean is: do we really have to do the update to the model manually.

As in the example, which means listen on a change or key... event and to 
call a method which updates the model (no other way to get the value back 
to the model)

I suppose this is the case, but of course this is much less comfortable 
than the current two way binding. 




Am Montag, 9. März 2015 09:25:20 UTC+1 schrieb AJ Mercer:
>
> 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] <javascript:>> 
> 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] <javascript:>.
>> To post to this group, send email to [email protected] 
>> <javascript:>.
>> 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