question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Two objects for bindLabel

See original GitHub issue

Expected behaviour

Hi Everyone, I would like to know if it was possible to add two object for bindLabel such like that instead of using ng template:

 <ng-select [items]="users | async" [multiple]="true" [closeOnSelect]="false" [hideSelected]="true" bindLabel="firstname email" bindValue="_id" placeholder="Select people" [(ngModel)]="userselected" name="sharedUser" required #sharedUser="ngModel">

Actual behaviour

For the moment I use ng template to add both but I would like to keep the same basic style.

                <ng-template ng-option-tmp let-item="item" let-index="index" let-search="searchTerm">
                  <h5>{{item.firstname}}  |  {{item.email}}</h5>
                </ng-template>

More Info

ng-select version: v2.0.0

browser: Mozilla 60.0.2 (64-bit)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
PierBJXcommented, Dec 19, 2018

In the component.ts, I get all the users from the server which are saved in a list of users (data variable). Then, I iterate through all the items of data and I add another element in the Object User bindName which combine firstname and lastname.

  ngOnInit() {
    this.currentUserId = this.auth.getUserDetails()._id;
    this.shared.changeShowInfo(false);
    this.api
      .getAllUsers()
      .takeUntil(this.destroy$)
      .subscribe(
        data => {
          for (let item in data) {
              data[item].bindName =
                data[item].firstname + " " + data[item].lastname;
              this.users.push(data[item]);
          }
        },
        err => {
          console.log(err);
        }
      );
}

In the HTML, bindLabel="bindName:

<ng-select [items]="users" [multiple]="true" [closeOnSelect]="false" [hideSelected]="true" bindLabel="bindName" bindValue="_id"
                    placeholder="Select people" [(ngModel)]="experiment.user_permission" name="sharedUser" required #sharedUser="ngModel">
             <ng-template ng-option-tmp let-item="item" let-index="index" let-search="searchTerm">
                      <h5>{{item.firstname}} {{item.lastname}}</h5>
             </ng-template>
</ng-select>
2reactions
HarounGazzahcommented, Mar 6, 2019

this.resourceService.getResources().subscribe(res => { let ress: any[]; ress = res; ress.map((i) => { i.fullName = i.firstname + ' ' + i.lastname; return i; }); this.resources = ress; });


<ng-select [items]="resources" [multiple]="true" name="resource" bindLabel="fullName" bindValue="reference" notFoundText="Aucun élément trouvé" typeToSearchText="tapez plus de 3 caractères pour trouver la resource" [loading]="resourcesLoading" [typeahead]="resourcesInput$" [(ngModel)]="positioning.resourceReference"> </ng-select>

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular 5 ng-select how to add two values to 'bindLabel'?
It is possible to display it via a custom label and item template: <ng-select [items]="users" bindLabel="firstName"> <ng-template ...
Read more >
@ng-select/ng-select - npm
Angular ng-select - All in One UI Select, Multiselect and Autocomplete. Latest version: 10.0.1, last published: a month ago.
Read more >
Ng Select - StackBlitz
Starter project for Angular apps that exports to the Angular CLI.
Read more >
Data sources
<ng-select [items]="people$ | async" bindLabel="name" autofocus bindValue="id" ... You can also set array of objects as items input ... Selected: "Two" ...
Read more >
Data binding basics - .NET MAUI - Microsoft Learn
NET MAUI data bindings allow properties of two objects to be linked so that a change in one causes a change in the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found