我想list
在点击关闭button
后添加项目。但点击后我想在添加项目后空白输入字段。这是我的代码
https://plnkr.co/edit/0sG16dVeHIWAvBjYpIjQ?p=preview
export class App {
title = 'Times point';
name ="hellxo";
val ="defual";
items=[];
onKeyP(event){
console.log(event.target.value);
this.val=event.target.value
}
addItem(){
if(this.val){
this.items.push(this.val);
this.val ='';
}
}
}
我已经做了空值但不工作this.val ='';
你可以使用 [value] ="val"。[value] 将您的输入值与 val 绑定。当 val 改变时,它会自动改变
使用这条线
<input type="text" name="" (keyup)="onKeyP($event)" [value]="val"/>
代替
<input type="text" name="" (keyup)="onKeyP($event)"/>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句