我正在使用角度4提示标签输入。我创建了一个api,它让我所有的用户列表,但我无法在角度提示列表中显示它。我很困惑该怎么做。需要帮助。
HTML
<input contenteditable="true" class="publisher-input" type="text"
id="comment" formControlName="comment"
placeholder="Add Your Comment" [mention]="userList"
[mentionConfig]="{triggerChar:'@',maxItems:10}" (searchTerm)="showUsers()">
TS
userList: String[] = [];
ngOnInit() {
this.loadUsers();
}
loadUsers() {
this.asd.getUsers().subscribe(results => {
results['success'].forEach(element => {
if (element.firstName && element.middleName && element.lastName) {
// tslint:disable-next-line:no-construct
this.userList.push(element.firstName + ' ' + element.middleName
+ ' ' + element.lastName);
}
if (!element.firstName) {
// tslint:disable-next-line:no-construct
this.userList.push(element.middleName + ' ' + element.lastName);
}
if (!element.middleName) {
// tslint:disable-next-line:no-construct
this.userList.push(element.firstName + ' ' + element.lastName);
}
if (!element.lastName) {
// tslint:disable-next-line:no-construct
this.userList.push(element.firstName + ' ' + element.middleName);
}
});
});
}
showUsers() {
this.loadUsers();
}
我使用了这个包https://github.com/dmacfarlane/angular-mentions。但是没有正确获取数据。
答案 0 :(得分:0)
您必须将searchTerm放在[mentionConfig]中,以使其工作
<input type="text" [mention]="userList" [mentionConfig]= {triggerChar:'@',mentionSelect:formatMention,maxItems:10,labelKey:'name',disableSearch:false}" name="text" id="text">