无法绑定到“占位符”,因为它不是“ ng-multiselect-dropdown”的已知属性

时间:2018-10-22 08:50:27

标签: angular angular2-services angular2-directives

我想实现自动完成功能,所以我发现一个相同的选项是使用多选下拉菜单。所以我用了这个模块-

https://www.npmjs.com/package/ng-multiselect-dropdown

但是在同上实施之后,我得到了这些错误-

错误-

ERROR Error: Uncaught (in promise): Error: Template parse errors:
Can't bind to 'placeholder' since it isn't a known property of 'ng- 
 multiselect-dropdown'.
1. If 'placeholder' is an Angular directive, then add 'CommonModule' 
 to the '@NgModule.imports' of this component.
2. To allow any property add 'NO_ERRORS_SCHEMA' to the 
'@NgModule.schemas' of this component. ("

<ng-multiselect-dropdown
[ERROR ->][placeholder]="'custom placeholder'"
  [data]="dropdownList"
  [(ngModel)]="selectedItems"
"): ng:///AdminLayoutModule/HierarchySearchComponent.html@7:0

当我在component.html中评论占位符时,出现此错误-

Can't bind to 'data' since it isn't a known property of 'ng- 
multiselect-dropdown'.
1. If 'data' is an Angular directive, then add 'CommonModule' to the 
'@NgModule.imports' of this component.
2. To allow any property add 'NO_ERRORS_SCHEMA' to the 
 '@NgModule.schemas' of this component.
   "
<ng-multiselect-dropdown
[placeholder]="'custom placeholder'"
  [ERROR ->][data]="dropdownList"
  [(ngModel)]="selectedItems"
  [settings]="dropdownSettings"
"): ng:///AdminLayoutModule/HierarchySearchComponent.html@8:2

类似的错误一直持续到最后一个属性。

更新

app.module.ts

import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { RouterModule } from '@angular/router';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';


import { AppRoutingModule } from './app.routing';
import { ComponentsModule } from './components/components.module';

import { AppComponent } from './app.component';

import { AdminLayoutComponent } from './layouts/admin-layout/admin-layout.component';

//-------------  Imported Modules -------------------------

import { NgMultiSelectDropDownModule } from 'ng-multiselect-dropdown';
import { CommonModule } from '@angular/common';


@NgModule({
  imports: [
    BrowserAnimationsModule,
    FormsModule,
    HttpModule,
    ComponentsModule,
    RouterModule,
    AppRoutingModule,
    NgbModule.forRoot(),
    NgMultiSelectDropDownModule.forRoot(),
    CommonModule,


  ],
  declarations: [
    AppComponent,
    AdminLayoutComponent,


  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

6 个答案:

答案 0 :(得分:2)

HierarchySearchComponent -这是您正在使用ng-multiselect-dropdown的组件。

所以您可能会有 HierarchySearch.module.ts

您只需从app.module.ts中的导入:[]中删除 NgMultiSelectDropDownModule.forRoot(),然后导入 HierarchySearch.module.ts

它将起作用。

答案 1 :(得分:1)

检查是否导入了NgMultiSelectDropDownModule到module.ts

import { NgMultiSelectDropDownModule } from 'ng-multiselect-dropdown';

@NgModule({


imports: [
    NgMultiSelectDropDownModule
  ],

答案 2 :(得分:1)

我遇到了这个问题并通过 添加

import { NgMultiSelectDropDownModule } from 'ng-multiselect-dropdown';

@NgModule({
imports: [
    NgMultiSelectDropDownModule
]
})

不导入组件的 xxxx.module.ts 文件,不导入 app.module.ts 文件

答案 3 :(得分:0)

通常,当您错过某些导入时会发生此错误。如果缺少,请添加以下行:

import { BrowserModule } from '@angular/platform-browser'; import { FormsModule } from '@angular/forms';

答案 4 :(得分:0)

在所有组件都已导入的ComponentsModule中添加多选导入。它对我有用。

答案 5 :(得分:0)

我也正在使用angular 7,但我的问题已解决。我只是导入NO_ERRORS_SCHEMA并将其包含在ng-multiselect-dropdown模块包含@NgModule的同一模块中:

import { NgModule ,NO_ERRORS_SCHEMA} from '@angular/core';
import { FormsModule } from '@angular/forms';


@NgModule({
  imports: [
    CommonModule,
    FormsModule,
    AngularMultiSelectModule,
  ],
  schemas:[NO_ERRORS_SCHEMA], 
})
export class SettingsModule { }