我正在使用最新版本的 JHipster 开发一个应用程序,我试图通过使用来自https://github.com/ng-select/ng-select{<ng-select>}
的模块来显示多选下拉列表。但它不显示。这是下面的代码。我的 app.module.ts 文件:
import { FormsModule } from '@angular/forms';
import { NgSelectModule } from '@ng-select/ng-select';
// jhipster-needle-angular-add-module-import JHipster will add new module here
import { JhiMainComponent, NavbarComponent, FooterComponent, PageRibbonComponent, ActiveMenuDirective, ErrorComponent } from './layouts';
@NgModule({
imports: [
BrowserModule,
NgSelectModule,
FormsModule,
MyAppAppRoutingModule,
Ng2Webstorage.forRoot({ prefix: 'jhi', separator: '-' }),
MyAppSharedModule,
MyAppCoreModule,
MyAppHomeModule,
MyAppAccountModule,
// jhipster-needle-angular-add-module JHipster will add new module here
MyAppEntityModule
],
declarations: [JhiMainComponent, NavbarComponent, ErrorComponent, PageRibbonComponent, ActiveMenuDirective, FooterComponent],
providers: [
-----------
],
bootstrap: [JhiMainComponent]
})
...........
数据服务:
export interface Person {
id: string;
isActive: boolean;
age: number;
name: string;
gender: string;
company: string;
email: string;
phone: string;
disabled?: boolean;
}
@Injectable({ providedIn: 'root' })
export class DataService {
.......
constructor(private http: HttpClient) {}
........
getPeople(term: string = null): Observable<Person[]> {
let items = getMockPeople();
if (term) {
items = items.filter(x => x.name.toLocaleLowerCase().indexOf(term.toLocaleLowerCase()) > -1);
}
return of(items).pipe(delay(500));
}
}
function getMockPeople() {
return [
{
'id': '5a15b13c36e7a7f00cf0d7cb',
'index': 2,
'isActive': true,
'picture': 'http://placehold.it/32x32',
'age': 23,
'name': 'Karyn Wright',
'gender': 'female',
'company': 'ZOLAR',
'email': 'karynwright@zolar.com',
'phone': '+1 (851) 583-2547'
},
{
'id': '5a15b13c2340978ec3d2c0ea',
'index': 3,
'isActive': false,
'picture': 'http://placehold.it/32x32',
'age': 35,
'name': 'Rochelle Estes',
'disabled': true,
'gender': 'female',
'company': 'EXTRAWEAR',
'email': 'rochelleestes@extrawear.com',
'phone': '+1 (849) 408-2029'
}
];
}
人员组件:
export class PeopleUpdateComponent implements OnInit {
people$3: Observable<any[]>;
selectedPeople3 = [];
constructor(
private jhiAlertService: JhiAlertService,
private dataService: DataService,
private activatedRoute: ActivatedRoute
) {}
ngOnInit() {
this.isSaving = false;
this.people$3 = this.dataService.getPeople();
}
}
我的html代码是:
<ng-select
[items]="people$3 | async"
bindLabel="name"
[multiple]="true"
[disabled]="disable"
[(ngModel)]="selectedPeople3">
</ng-select>
任何帮助表示赞赏