3 回答
![?](http://img1.sycdn.imooc.com/54584dad0001dd7802200220-100-100.jpg)
TA贡献1806条经验 获得超5个赞
.html
<input type="text" (input)="inputMthd($event)" (keyup)="methodCalled($event)">
.ts
inputMthd(e){
console.log(e);
event.target.value.length;
}
methodCalled(e){
console.log(e);
e.target.value.length;
}
![?](http://img1.sycdn.imooc.com/5333a0350001692e02200220-100-100.jpg)
TA贡献1786条经验 获得超13个赞
您ngModel需要绑定到panels不panel中ngFor。您可以使用index.
<div *ngFor="let panel of panels; index as i" class="panel" [id]="'panel-' + panel.id">
<div>{{ panel.title }}</div>
<input matInput placeholder="Bezeichnung" [(ngModel)]="panels[i].title" (blur)="showAlert(i)" />
</div>
然后通过传入索引并使用它来获取面板标题的长度来触发组件中的警报。我在blur这里使用了这个事件。
showAlert(index) {
const titleLength = this.panels[index].title.length;
// Call alert with the length of the title here.
}
![?](http://img1.sycdn.imooc.com/545863e80001889e02200220-100-100.jpg)
TA贡献1821条经验 获得超6个赞
尝试这个,
<div *ngFor="let panel of panels; index as i" class="panel" [id]="'panel-' + panel.id">
<div>{{ panel.title }}</div>
<input (change)="onChange({{panel.title}})" matInput placeholder="Bezeichnung" [(ngModel)]="panel.title" />
</div>
onChange(title) {
console.log(title.length);
})
添加回答
举报