我想在文本框的输入更改时调用类型脚本函数,它对我有用。但它需要每次更改,我想在文本框中的最小字符数为 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)">