angular - 单击任何字母时的角度提及触发器
问题描述
在我的 angular 项目中,我使用 angular-mention 库来建议用户名。@
如果我输入或,它工作正常#
。只有当我输入@或#时,它才会给我用户列表。
但我不想输入@
or #
。我想输入任何字母,这样它就会给我所需的结果。假设如果我输入 j,那么它将给我所有以字符 J 或 j 开头的用户名列表。
谁能帮我这个?
您可以在此处参考此工作代码...链接。
上面的链接是我可用的工作示例,但它仅在我输入 @ 时才有效,我想在输入任何字符时工作
另外,我尝试如下
<input type="text" class="searchBox" [mention]="items" [mentionConfig]="{triggerChar:''}" placeholder="Search user" [(ngModel)]="searchText" />
在上面的代码triggerChar中,如果我输入@或#,我需要输入一些值,它会按照它工作。但是为任何我不知道该怎么做的角色工作?
解决方案
您可以通过修改库来做到这一点。我认为这是不应该推荐的臭脏黑客。但如果你真的想要它...
该angular-mention
库triggerChar
用作索引提及列表的键。
// in file "angular-mentions/src/lib/mention.directive.ts"
let config = this.triggerChars[charPressed]; <= locate this line
/* custom code start */
const yourTriggerCharList = ['a', 'b', ...
if (yourTriggerCharList.indexOf(charPressed) >= 0 && !config && !this.searching) {
config = this.triggerChars[anExistingTriggerChar];
}
/* custom code end */
if (config) { // <= triggerChar found
... (showing search list)
推荐阅读
- c - C 返回大数混淆
- r - 使用 lubridate 和 ggplot 在条形图中的工作日顺序
- javascript - 在数组数组中返回数组名称
- ubuntu - Ubuntu16.04 - 未满足的依赖项 - apt-get -f install 也会引发错误
- php - 使用 SRDB 工具时出现“服务器请求客户端未知的身份验证方法”错误
- python - 从几个列表中创建熊猫数据框
- ruby-on-rails - 启用增强语言指标后,为什么在 heroku (rails) 控制台中出现 NameError?
- eclipse - JDBC、Servlet/我如何向 MySQL 插入数据?
- r - R OpenCV中顺序JPEG的SOS参数无效
- java - 如何在 MacOSX 上处理 R 代码中的 Java 错误?