ng-ytl-zorro-antd
Version:
An enterprise-class UI components based on Ant Design and Angular
54 lines (47 loc) • 1.55 kB
text/typescript
import {Component, ViewChild, ElementRef} from '@angular/core';
import { NzInputDirectiveComponent } from '../../components/input/nz-input.directive.component';
export class NzDemoTagControlComponent {
public tags = ['Unremovable', 'Tag 2', 'Tag 3'];
public inputVisible = false;
public inputValue = '';
input: NzInputDirectiveComponent;
handleClose(removedTag: any): void {
this.tags = this.tags.filter(tag => tag !== removedTag);
}
sliceTagName(tag: string): string {
const isLongTag = tag.length > 20;
return isLongTag ? `${tag.slice(0, 20)}...` : tag;
}
showInput(): void {
this.inputVisible = true;
setTimeout(() => {
this.input.nativeElement.focus();
}, 10);
}
handleInputConfirm(): void {
if (this.inputValue) {
this.tags.push(this.inputValue);
}
this.inputValue = '';
this.inputVisible = false;
}
}