首页 > 解决方案 > 子项目primeng上的角度下拉选择菜单错误

问题描述

我一直在尝试使用角度和反应形式(角度 10)在表单中设置子项的选择下拉菜单,但我尝试哪种方法(ng-select、角度多选、CdkVirtualScrollViewport 等)并不重要我可以' t 似乎可以这样做。我只能做一个普通的 HTML 选择,但由于下拉列表包含 5K 项,整个加载大约需要 6 秒,这是不可接受的。我正在尝试的最新是primeng的下拉列表,但即使是这个例子似乎也不起作用,下面是我的问题的一个片段......

ts.file contains
interface City {
  name: string,
  code: string
}
...
export class CreateFullOrderComponent implements OnInit {
...
cities: City[];
selectedCity: City;
....

constructor(
.....
this.cities = [
      {name: 'New York', code: 'NY'},
      {name: 'Rome', code: 'RM'},
      {name: 'London', code: 'LDN'},
      {name: 'Istanbul', code: 'IST'},
      {name: 'Paris', code: 'PRS'}
  ];
......

HTML file..
....
 <td>
    <p-dropdown [options]="cities" [(ngModel)]="selectedCity" optionLabel="name"></p-dropdown>
  </td>
......

the built works fine, however I get the following error in my chrome console..
main-es2015.41e78b833c373dc8af88.js:152077 ERROR TypeError: Cannot read property '_rawValidators' of null
    at getControlValidators (main-es2015.41e78b833c373dc8af88.js:5144)
    at setUpValidators (main-es2015.41e78b833c373dc8af88.js:5764)
    at setUpControl (main-es2015.41e78b833c373dc8af88.js:5689)
    at FormGroupDirective.addControl (main-es2015.41e78b833c373dc8af88.js:8877)
    at NgModel._setUpControl (main-es2015.41e78b833c373dc8af88.js:8298)
    at NgModel.ngOnChanges (main-es2015.41e78b833c373dc8af88.js:8258)
    at NgModel.rememberChangeHistoryAndInvokeOnChangesHook (main-es2015.41e78b833c373dc8af88.js:147472)
    at callHook (main-es2015.41e78b833c373dc8af88.js:148484)
    at callHooks (main-es2015.41e78b833c373dc8af88.js:148451)
    at executeInitAndCheckHooks (main-es2015.41e78b833c373dc8af88.js:148402)

我的形象看起来像......

在此处输入图像描述

我不确定这是否重要,但我在大多数其他尝试过的下拉菜单中都遇到了这个错误,我的理解是问题出在 [(ngModel)]="selectedCity" 上,就好像我删除了我赢得的那个声明'没有得到错误,即使它仍然下拉不工作。

我很感激任何帮助推进这个..

标签: angularformslazy-loadingdropdown

解决方案


推荐阅读