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.