ng2-tag-input separatorKeys不起作用



我正在尝试使用ng2-tag-input模块,具有非常基本的配置:

import { Component } from '@angular/core';
@Component({
  moduleId: module.id,
  selector: 'search-form',
  template: `<tag-input [(ngModel)]='items'></tag-input>`
})
export class SearchFormComponent {

    items = ['Pizza', 'Pasta', 'Parmesan'];
    options = {
        placeholder: "+ term",
        secondaryPlaceholder: "Enter a new term",
        separatorKeys: [32,13]
    }
    onItemAdded(item) {
    }
    onItemRemoved(item) {
    }

}

一切工作,除了separatorKeys -它没有效果,当我输入space key (keyCode=32)时,它的行为就像一个普通的空格而不是分隔符。

在演示页面上,他们的例子工作得很好,这是与NG2版本相关的东西吗?

https://github.com/Gbuomprisco/ng2-tag-input

我是这个模块的作者。

似乎你没有在模板中设置separatorKeys属性。查看http://www.webpackbin.com/NJy38G8kM获取源代码。

添加separatorKeys到html模板

@Component({
  moduleId: module.id,
  selector: 'search-form',
    template: `<tag-input [(ngModel)]='items'
                          [separatorKeyCodes]="[32,13]"></tag-input>`
})

最新更新