0

I am trying to use ngl-lookup of the ngl-lightning library i want to pass an array of type any[] instead of String[], this is my code:

 <ngl-lookup [lookup]="lookupManagerUsers" [icon]="true" [image]="'user'" [noResultsText]="'Aucun résultat trouvé'"
            [(pick)]="pickedManagerUser" (pickChange)="managerUserPicked($event)" placeholder="Recherchez un agent..." formControlName="manager_id"
            ngDefaultControl>
            <ng-template nglLookupItem let-item>
              <div class="slds-media__body">
                <span class="slds-media__figure slds-listbox__option-icon">
                  <span class="slds-icon_container slds-icon-standard-user">
                    <svg class="slds-icon slds-icon_small" aria-hidden="true">
                      <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/assets/icons/standard-sprite/svg/symbols.svg#user" />
                    </svg>
                  </span>
                </span>{{item}}
              </div>
            </ng-template>
 </ngl-lookup>

and this is my method pickedManagerUser: string = '';

lookupManagerUsers = (query: string, source = this.manager_users): any[] => {
let temp = [];
if (!query) {
  temp = source;
} else {
  const temp2 = source.filter(user => user.first_name.indexOf(query.toLowerCase()) > -1 || user.last_name.indexOf(query.toLowerCase()) > -1);
  for (const m of temp2) {
    temp.push(m);
  }
}
return temp;}


 managerUserPicked(superhero) {
console.log(superhero); }

but this is really my problem : enter image description here

any help please

Ilyes Atoui
  • 474
  • 2
  • 9
  • 29

2 Answers2

1

Try to print a specific property instead of the whole item, ie {{ item.first_name}} instead of the whole item as {{ item }}.

bekos
  • 1,303
  • 1
  • 13
  • 11
  • yes i tried that and it work but my problem that when i select a item i want to get the object by this method (pickChange)="managerUserPicked($event)" and not just the first_name – Ilyes Atoui Feb 14 '19 at 09:22
0

thanks to bekos i fixed the problem and changed my code to

 <ngl-lookup [lookup]="lookupManagerUsers" [icon]="true" [image]="'user'" [noResultsText]="'Aucun résultat trouvé'"
            [pick]="pickedManagerUser" (pickChange)="managerUserPicked($event)" placeholder="Recherchez un agent..." formControlName="manager_id"
            ngDefaultControl>
            <ng-template nglLookupItem let-item>
              <div class="slds-media__body">
                <span class="slds-media__figure slds-listbox__option-icon">
                  <span class="slds-icon_container slds-icon-standard-user">
                    <svg class="slds-icon slds-icon_small" aria-hidden="true">
                      <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/assets/icons/standard-sprite/svg/symbols.svg#user" />
                    </svg>
                  </span>
                </span>{{item.first_name}} {{item.last_name}}
              </div>
            </ng-template>
          </ngl-lookup>

and this function to

managerUserPicked(managerUserPicked) {
if (managerUserPicked) {
  this.pickedManagerUser = managerUserPicked.first_name + ' ' + managerUserPicked.last_name;
  console.log(managerUserPicked);
} else {
  this.pickedManagerUser = null;
}}

enter image description here enter image description here

Ilyes Atoui
  • 474
  • 2
  • 9
  • 29