我想在文本框的输入更改时调用类型脚本函数,它对我有用。但它会在每次更改时调用,我想在文本框中的最小字符数为 5 时调用。
export class StudentMaintenanceComponent implements OnInit {
@Component({
selector: 'app-student-management',
template: `<input placeholder="" class="form-control" type="text" [maxlength]="5" (input)="SearchData($event.target.value)">`,
styleUrls: ['./app-student-management.css']
})
SearchData(_no: string) { // should be called when minimum no of character are 5 in the text field.
console.log(_no);
}
}
最佳答案
你可以这样写
(input)="$event.target.value.length > 5 && SearchData($event.target.value)"
你也可以像这样使用模板引用变量
<input placeholder="" #textInput class="form-control" type="text" [maxlength]="5" (input)="textInput.value.length > 5 && SearchData(textInput.value)">
关于typescript - 如何在角度2的输入文本变化时调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48083525/