简体   繁体   English

Angular ng-select标签输入-需要创建标签onfocusout

[英]Angular ng-select tag input - need to create tag onfocusout

In ng-select , user need to hit enter key after typing to create a tag.ng-select中,用户需要在输入后按回车键来创建标签。 But in my scenario tags also need to be created when user remove the focus from ng-select element after typing (When user type and leave without press enter key).但是在我的场景中,当用户在输入后从ng-select元素中移除焦点时,也需要创建标签(当用户输入并离开时不按回车键)。 Here is the HTML part.这是 HTML 部分。 Using this inside a angular reactive form.在 angular 反应形式中使用它。

<ng-select placeholder="Tags" [items]="[]" [addTag]="true" [multiple]="true" [selectOnTab]="true" [isOpen]="false" formControlName="tags"> </ng-select>

Please let me know your ideas.. Thanks you.请让我知道你的想法。谢谢。

You could use the "blur" event as described in the ng-select repo您可以使用ng-select repo 中描述的“模糊”事件

You would just have to add (blur)="someEvent()" to your ng-select.您只需将 (blur)="someEvent()" 添加到您的 ng-select 中。

EDIT:编辑:

To listen to a keypress on the enter key you can do this:要收听 Enter 键上的按键,您可以执行以下操作:

Do you mean to listen for an enter keypress event?你的意思是听一个输入按键事件吗? Absolutely!绝对地!

You can use the keyup event:您可以使用 keyup 事件:

(keyup)="someAction($event)"

Then in the component you can do something like this:然后在组件中您可以执行以下操作:

someAction(event) {
    if (e.keyCode === 13) {
        // enter key was pressed
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM