以下是一个示例代码:
var SampleComponent7 = ng.core.Component({
selector: "sampleseven",
template: "<input [(value)]='name' /><input (click)='clicked()' value='Click here' type='submit' />"
}).Class({
constructor: function(){
this.name = "";
},
clicked: function(){
alert(this.name);
}
})
即使我在输入框中输入了一些值,警告框似乎总是打印空字符串。我错过了什么吗?
答案 0 :(得分:0)
我会将以下内容与[(ngModel)]
一起使用,而不是[(value)]
:
var SampleComponent7 = ng.core.Component({
selector: 'sampleseven',
template: '<input [(ngModel)]="name" /><input (click)="clicked()" value="Click here" type="submit" />'
}).Class({
constructor: function(){
this.name = "";
},
clicked: function(){
alert(this.name);
}
});
请参阅此plunkr:https://plnkr.co/edit/PevjoFUasncybPGnVkU0?p=preview。