我正在使用 Angular 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。但没有正确获取数据。