首页 > 解决方案 > 如何使用角度创建搜索栏

问题描述

搜索 : ____________

我想创建一个搜索栏,当用户尝试输入等于或大于 8 个字的输入文本时,它应该触发并存储变量并重置搜索栏并检查后端 API 并且在后端找到一个,然后它应该显示如果未找到计数增量或 ELSE,则应显示在表中。

注意:我想在没有搜索按钮的情况下触发它,并且不应该计算空格。

例如:

搜索:qwerr121

找到:计数:1

未找到表:qwerr121

if text == 16:检查后端找到 = found + 1 else:array = [qwerr121]

谢谢

这是我的 js 代码,但我该如何处理 Angular

   JS code: 
const input = document.getElementById('input');
let data;
 
input.addEventListener('input', (e) => {
  const inputValue = e.target.value;
 
  if (inputValue.length === 11) {
    data = inputValue;
 
    e.target.value = '';
  }
});
Html: 
<input type="text" id="input">

标签: javascripthtmlangular

解决方案


我不知道这是否是你要找的,但我做了这个https://stackblitz.com/edit/angular-ivy-zbuypx?file=src/app/app.component.html


推荐阅读