【问题标题】:Can't bind to 'settings' since it isn't a known property of 'angular2-multiselect'无法绑定到“设置”,因为它不是“angular2-multiselect”的已知属性
【发布时间】:2021-09-15 03:40:13
【问题描述】:

每个人 我正在尝试使用 angular2-multiselect 并遇到问题。 我的角度版本是 11

这是问题信息

Error: src/app/main/stores/stores-list/new-stores-sidebar/new-stores-sidebar.component.html:367:35 - error NG8002: Can't bind to 'data' since it isn't a known property of 'angular2-multiselect'.
1. If 'angular2-multiselect' is an Angular component and it has 'data' input, then verify that it is part of this module.
2. If 'angular2-multiselect' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component.

367             <angular2-multiselect [data]="itemList"
                                      ~~~~~~~~~~~~~~~~~

  src/app/main/stores/stores-list/new-stores-sidebar/new-stores-sidebar.component.ts:11:16
    11   templateUrl: './new-stores-sidebar.component.html'
                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Error occurs in the template of component NewStoresSidebarComponent.


Error: src/app/main/stores/stores-list/new-stores-sidebar/new-stores-sidebar.component.html:369:15 - error NG8002: Can't bind to 'settings' since it isn't a known property of 'angular2-multiselect'.      
1. If 'angular2-multiselect' is an Angular component and it has 'settings' input, then verify that it is part of this module.
2. If 'angular2-multiselect' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component.

369               [settings]="settings"
                  ~~~~~~~~~~~~~~~~~~~~~

  src/app/main/stores/stores-list/new-stores-sidebar/new-stores-sidebar.component.ts:11:16
    11   templateUrl: './new-stores-sidebar.component.html'
                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Error occurs in the template of component NewStoresSidebarComponent.

这是问题图片

这是html代码。

<angular2-multiselect [data]="itemList"
  [(ngModel)]="selectedItems" 
  [settings]="settings" 
  (onSelect)="onItemSelect($event)"
  (onDeSelect)="OnItemDeSelect($event)" 
  (onSelectAll)="onSelectAll($event)" 
  (onDeSelectAll)="onDeSelectAll($event)">
</angular2-multiselect>

这是 .ts 代码

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

@Component({
  selector: 'app-new-stores-sidebar',
  templateUrl: './new-stores-sidebar.component.html'
})

export class NewStoresSidebarComponent implements OnInit {
  public itemList = [];
  public selectedItems = [];
  public settings = {};

  /**
   * Constructor
   *
   * @param {CoreSidebarService} _coreSidebarService
   */
  constructor(
    private _coreSidebarService: CoreSidebarService,
    private _toastr: ToastrService
  ) {
    
  }

  ngOnInit() {
    this.closeImage = 'assets/images/close.png';

    this.itemList = [
      { "id": 1, "itemName": "India", "category": "asia" },
      { "id": 2, "itemName": "Singapore", "category": "asia pacific" },
      { "id": 3, "itemName": "Germany", "category": "Europe" },
      { "id": 4, "itemName": "France", "category": "Europe" },
      { "id": 5, "itemName": "South Korea", "category": "asia" },
      { "id": 6, "itemName": "Sweden", "category": "Europe" }
    ];

    this.selectedItems = [
      { "id": 1, "itemName": "India" },
      { "id": 2, "itemName": "Singapore" },
      { "id": 4, "itemName": "Canada" }
    ];

    this.settings = {
      singleSelection: false,
      text: "Select Fields",
      selectAllText: 'Select All',
      unSelectAllText: 'UnSelect All',
      searchPlaceholderText: 'Search Fields',
      enableSearchFilter: true,
      badgeShowLimit: 5,
      groupBy: "category"
    };
  }

  loadDataSet1(){
    this.selectedItems = [];
    this.itemList = [ { "id": 1, "itemName": "Apple", "category": "fruits" },
      { "id": 2, "itemName": "Banana", "category": "fruits" },
      { "id": 5, "itemName": "Tomatoe", "category": "vegetables" },
      { "id": 6, "itemName": "Potatoe", "category": "vegetables" }];
  }
  loadDataSet2(){
    this.selectedItems = [];
    this.itemList = [
      { "id": 1, "itemName": "India", "category": "asia" },
      { "id": 2, "itemName": "Singapore", "category": "asia pacific" },
      { "id": 3, "itemName": "Germany", "category": "Europe" },
      { "id": 4, "itemName": "France", "category": "Europe" },
      { "id": 5, "itemName": "South Korea", "category": "asia" },
      { "id": 6, "itemName": "Sweden", "category": "Europe" }
    ];
  }
  onItemSelect(item: any) {
    console.log(item);
    console.log(this.selectedItems);
  }
  OnItemDeSelect(item: any) {
    console.log(item);
    console.log(this.selectedItems);
  }
  onSelectAll(items: any) {
    console.log(items);
  }
  onDeSelectAll(items: any) {
    console.log(items);
  }
}

【问题讨论】:

  • 我也有同样的问题。有什么解决办法吗?我想这取决于版本。
  • 确保你已经在你的app/tests中导入了相应的模块。

标签: angular frontend angular2-template


【解决方案1】:

我想你做了......但是......以防万一:

您是否在 app.module.ts 中导入了 AngularMultiSelectModule?:

app.module.ts

import { AngularMultiSelectModule } from 'angular2-multiselect-dropdown';

@NgModule({
  // ...
  imports: [
    AngularMultiSelectModule,
  ]
  // ...
})

Source

【讨论】:

  • 是的,我已经在app.module.ts中添加了,但是它不起作用。
  • 我认为这是角度版本问题
  • 我的角度版本是 11
猜你喜欢
  • 1970-01-01
  • 2017-09-01
  • 2017-02-26
  • 2017-02-27
  • 2016-05-15
  • 2019-03-26
  • 2016-12-30
  • 2017-06-21
  • 2016-12-21
相关资源
最近更新 更多