The displayed value of the nb-select component is not up to date.
See original GitHub issueIssue 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:
- Created 4 years ago
- Reactions:6
- Comments:5
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Update:
https://github.com/akveo/nebular/issues/2145#issuecomment-622490714
I just changed [(selected)] to [(ngModel)] and it works for me.