问题可能是由于多选下拉框未更新所致。可以尝试在代码中使用ChangeDetectorRef来手动触发更改检测。
示例代码:
import { Component, ChangeDetectorRef } from '@angular/core';
@Component({ selector: 'app-component', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent {
// Codes for dynamic adding of items to ng-multiselect-dropdown
public ngOnInit(): void { // ... }
public addToSelected(): void { // Add new item to array // ...
// Trigger change detection
this.changeDetectorRef.detectChanges(); // Add this line
}
constructor(private changeDetectorRef: ChangeDetectorRef){}
}