如何从服务中填写我的下拉菜单?

时间:2019-02-14 23:01:23

标签: ng-dropdown-multiselect

我正试图从客户端服务中填充ng-multiselect-dropdown,我可以从数据库中获取客户端,但是我不知道发送ID和名称以填充列表的正确语法!

我已经尝试了很多例子,但是都没有成功,

到目前为止我尝试过的是:

    this.dropdownList = 
         this.clientService.getClients().subscribe(
      data => this.clients = data,
      error => console.log(error),
     () => this.isLoading = false

     )};

这是我的服务文件

     getClients(): Observable<Client[]> {
     return this.HttpClient.get<Client[]>('/api/clients');}

型号:

     export class Client {
     _id?: string;
     name?: string;
     address?: string;
     zipcode?: number;
     city?: string;
     email?: string;
     phone?: string;
     }

HTML:

    <ng-multiselect-dropdown
    [placeholder]="'custom placeholder'"
    [data]="clients"
    [selectedItems]=selectedItems;
    [settings]="dropdownSettings"
    (onSelect)="onItemSelect($event)"
    (onSelectAll)="onSelectAll($event)"
     >
     </ng-multiselect-dropdown >


     [Populated with [data]= clients[https://imgur.com/a/D1WFMlw] 

我希望有一个函数(this.dropdownList =)并从服务中填充我的列表。到目前为止,我已经填充了一个clients对象列表,我需要填充客户端名称和id :)

谢谢大家。

0 个答案:

没有答案