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.

nb-select not working with dynamic data

See original GitHub issue

Issue type

I’m submitting a … (check one with “x”)

  • [x ] bug report
  • feature request

Issue description

Nb-Select not working with dynamic data The form is loaded/created, then data is fetched from database and put in the form, the select option not changing after fetching the data Current behavior:

countryCode = null countriesList = null no option selected after the data is fetched

countryCode = PK slected option does not change to PK Expected behavior:

The option with value PK should be selected

Related code: Here is the sample code, this also not working stackblitz

Other information:

npm, node,

Node 10
Angular 7
Nebular 3

OS Browser OS - Ubuntu 18.04 Browsers - Chrome, Mozillah

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:15 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
sameerpallavcommented, Oct 19, 2019

Why is this closed? nb select still doesnt work with dynamic data

0reactions
rardila-uniajccommented, Jun 4, 2021

how? what versión?

version 6.2.1. I think it works even on 5.1.0. The reason why it works for me is because I do the following.

// Make sure it says static true, to access it in ngOnInit
@ViewChild('selectComponent', { static: true })
public selectComponent: NbSelectComponent = null;

// If you want to, you can emit the change function again in ngAfterViewInit.
// or you can fetch the data in ngOnInit and emit the change to the component. Since the ViewChild is static
// you can reference it in NgOnInit as well.
public ngAfterViewInit()
{
    this.selectComponent.selectedChange.emit(SELECTED_VALUE);
}

// or you can fetch the data and set a timeout.
setTimeout(() =>
{
    this.selectedDialogueComponent.selectedChange.emit(SELECTED_VALUE);
},1000);

If you do the following things it should work. this is what I do. good luck!

Thanks for response but it didn’t work for me… Anyway i found another way to fix it

static setOptionNbSelect(selectComponent: NbSelectComponent, optToCompare: any) {
        setTimeout(() => {
            if (selectComponent) {
                const selectedOptions: NbOptionComponent[] = [];
                for (const option of selectComponent.options['_results']) {
                    if (_.isEqual(optToCompare, option['value'])) {
                        selectedOptions.push(option);
                        break;
                    }
                }
                for (const option of selectedOptions) {
                    selectComponent['selectOption'](option);
                }
                selectComponent['cd'].detectChanges();
            }
        }, 500);
        
    }

I hope it works for someone else.

what’s the _ underscore in _.isEqual(optToCompare, options[‘results’]). ??

Hi @bluriverIt

npm i lodash npm i --save-dev @types/lodash

import * as _ from ‘lodash’;

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to set a preselected option with Nebular, nb-select
There exists an issue with dynamic data, but with static data, it works as described in the documentation you mentioned: HTML: <nb-select ......
Read more >
Select Angular UI Component - Nebular - GitHub Pages
The NbSelectComponent provides a capability to select one of the passed items. ... In this case, nb-select will work only with arrays -...
Read more >
Cypress Select from Dynamic Drop Down - ProgramsBuzz
Static dropdown have <select> tag while dynamic dropdown can have <nb-select>, <ng-select> or any other tag. Static dropdown with select tag ...
Read more >
E Select Default Value - StackBlitz
<nb-layout-column>. <nb-select [(selected)]. ="selectedOption">. <nb-option *ngFor="let o of. options" [value]="o">. {{ o.name }}. </nb-option>. </nb-select>.
Read more >
[Gaming NB/DT] Armoury Crate Introduction (Ver5.0) - ASUS
GPU Mode①: Thru the GPU mode switching, gamers can select in the ... to collect problem log and user can click "Generate log...
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