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.

The displayed value of the nb-select component is not up to date.

See original GitHub issue

Issue type

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

  • bug report
  • feature request

Issue description

Refreshing the options of the nb-select component

Current behavior: The selected element is not updated, however the “ngModel” or “selected” corresponds to the element.

Expected behavior: The value of the select displayed corresponds to the selected value.

Steps to reproduce: Update the value containing the options of the nb-select. The option array must not have the same object reference.

Related code:

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-test',
  templateUrl: './test.component.html',
  styleUrls: ['./test.component.scss']
})
export class TestComponent implements OnInit {
  public selected = { key: 1 };

  public defaultOptions = [];

  public options1 = [
    { key: 1, label: 'Key 1 selected' },
    { key: 2, label: 'Key 2 selected' },
    { key: 3, label: 'Key 3 selected' },
    { key: 4, label: 'Key 4 selected' },
    { key: 5, label: 'Key 5 selected' }
  ];

  public options2 = [
    { key: 6, label: 'Key 6 selected' },
    { key: 7, label: 'Key 7 selected' },
    { key: 8, label: 'Key 8 selected' },
    { key: 9, label: 'Key 9 selected' },
    { key: 10, label: 'Key 10 selected' }
  ];
  public i = 0;

  constructor() {}

  ngOnInit() {
    setInterval(() => {
      if (this.isOdd(this.i)) {
        this.defaultOptions = this.options1;
      } else {
        this.defaultOptions = this.options2;
      }
      this.i++;
    }, 2000);
  }

  isOdd(num: number) {
    return num % 2;
  }
}

test.component.ts

<select [(ngModel)]="selected.key">
  <option *ngFor="let column of defaultOptions" [value]="column.key" class="inline-filter">{{column.label}}</option>
</select>

<nb-select [(selected)]="selected.key" *ngIf="defaultOptions.length > 0">
  <nb-option *ngFor="let column of defaultOptions" [value]="column.key">
    {{column.label}}
  </nb-option>
</nb-select>

<nb-select [(ngModel)]="selected.key" *ngIf="defaultOptions.length > 0">
  <nb-option *ngFor="let column of defaultOptions" [value]="column.key">
    {{column.label}}
  </nb-option>
</nb-select>

<br><br>
Selected Key = {{selected.key}}

<pre>
  {{defaultOptions | json}}
</pre>

test.component.html

Other information:

In the example above the select HTML 5 is well updated compared to the nb-select (with ngModel or selected)

npm, node, OS, Browser

<!--
Node, npm: v12.13.0, v6.13.0
OS: Ubuntu 18.04.3 LTS
Browser: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) angular-electron/6.3.1 Chrome/78.0.3905.1 Electron/7.0.0 Safari/537.36"
-->

Angular, Nebular

<!--
    "@nebular/bootstrap": "^4.4.0",
    "@nebular/eva-icons": "4.5.0",
    "@nebular/theme": "4.5.0",

-->

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:6
  • Comments:5

github_iconTop GitHub Comments

1reaction
fofiedellycommented, May 1, 2020

Update:

I was facing exactly the same issue also yesterday. If you are using FormControls you can set the value of the nb-select in your component and it will work. step1: this.fb.group({ shop: [this.getDefaultElement(this.shoe.shop), [Validators.required]],....

https://github.com/akveo/nebular/issues/2145#issuecomment-622490714

0reactions
asawicki96commented, Feb 2, 2021

I just changed [(selected)] to [(ngModel)] and it works for me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React-select component value not updating. - Stack Overflow
When I select a value out of the list the component input field is not being filled in with the value. class Search...
Read more >
<input type="date"> - HTML: HyperText Markup Language
Value. A string representing the date entered in the input. · Additional attributes. The attributes common to all <input> elements apply to the ......
Read more >
Select - Ant Design
Select component to select value from options. When To Use. A dropdown menu for displaying choices - an elegant alternative to the native...
Read more >
Advanced options - Microsoft Support
Editing options. After pressing Enter, move selection Makes an adjacent cell the next active cell after you press ENTER in the current active...
Read more >
Form Components - Form.io Documentation
Learn about the Form Components and the settings available within the Form Components. ... The Select displays a list of values in a...
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