Angular 角度2-Can';t绑定到';设置';因为它不是';t'的已知属性;我的数据表';

Angular 角度2-Can';t绑定到';设置';因为它不是';t'的已知属性;我的数据表';,angular,Angular,我想使用警卫和高级路由,所以我遵循了官方的路由教程 我创建了一个模块,将与我的组件相关的所有内容都放在里面 (customers.routing.ts、customers.service.ts、customers.component.ts.) 由于它返回该错误: Unhandled Promise rejection: Template parse errors: Can't bind to 'settings' since it isn't a known property of 'my-da

我想使用警卫和高级路由,所以我遵循了官方的路由教程

我创建了一个模块,将与我的组件相关的所有内容都放在里面 (customers.routing.ts、customers.service.ts、customers.component.ts.)

由于它返回该错误:

Unhandled Promise rejection: Template parse errors:
Can't bind to 'settings' since it isn't a known property of 'my-datatable'.
1. If 'my-datatable' is an Angular component and it has 'settings' input, then verify that it is part of this module.
2. If 'my-datatable' 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. ("v *ngIf="customers">
        <div class="customersDataTableWrapperDiv">
            <my-datatable [ERROR ->][settings]="tableSettings" (onError)="onDataTableError($event)" ></my-datatable>
        </div>
   "): ng:///CustomersModule/CustomersComponent.html@11:26
'my-datatable' is not a known element:
1. If 'my-datatable' is an Angular component, then verify that it is part of this module.
2. If 'my-datatable' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("
    <div *ngIf="customers">
        <div class="customersDataTableWrapperDiv">
            [ERROR ->]<my-datatable [settings]="tableSettings" (onError)="onDataTableError($event)" ></my-datatable>
     "): ng:///CustomersModule/CustomersComponent.html@11:12 ; Zone: <root> ; Task: Promise.then ; Value: Error: Template parse errors:
但是app.module.ts已经使用了DataTableComponent,我没有删除它

这是我创建的模块(现在在app.module.ts中引用该模块进行导入):

我会错过什么? 谢谢

[编辑:这是我的DataTableModule:

import { NgModule } from '@angular/core';
import { DataTableComponent } from './dataTable.component';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { ReactiveFormsModule } from '@angular/forms';

@NgModule({
    imports: [CommonModule,FormsModule,ReactiveFormsModule],
    declarations: [DataTableComponent],
    exports: [DataTableComponent]
})
export class DataTableModule{
}

]

您应该将
DatatableComponent
添加到模块中:

@NgModule({
    imports: [],
    declarations: [DatatableComponent],
    exports: [DatatableComponent]
})
export class DatatableModule{
}
在您的视图中,导入模块:
DatatableModule

@NgModule({
    imports: [DatatableModule],
    declarations: [],
    exports: []
})
export class MyCurrentViewModule{
}
更新1:

尝试将
CommonModule
添加到您的
DatatableModule
,如下所示:

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { DatatableComponent } from './datatable.component';

@NgModule({
    imports: [
        CommonModule
    ],
    declarations: [DatatableComponent],
    exports: [DatatableComponent]
})
export class DatatableModule{
}

“app.module.ts已经使用了DataTableComponent”面临着类似的情况。正在等待包含错误原因的答案。@SaiyaffFarouk我更新了我的答案,请看一看。也请查看我的评论。希望能有帮助!;)这实际上解决了我的场景中的问题。但是,如果DatatableComponent在整个应用程序中使用并且在app.module.ts中声明,为什么会发生此错误?为什么要在特定模块中声明它?@ninja我已经更新了我的答案。您可以创建
DatatableModule
。然后将其导入要使用
DataTables
的位置。例如,如果您在
UserComponent
中,那么在
UserModule
中,您必须
导入我们创建的
DatatableModule
。@ninja不,我指的是当前组件。无论如何,如果您像我在示例中所做的那样创建
DatatableModule
,并将其添加到
imports
中的
AppModule
中,它应该可以工作。希望有帮助!我将导入添加到app.module.ts,我得到了由模块“AppModule”导入的意外指令“DataTableComponent”。请添加@NgModule注释。@ninja您正在
AppModule
中导入
DatatableComponent
。您必须导入
DatatableModule
。这就是为什么。按照我回答中的例子来做。首先像我那样创建一个
DatatableModule
,然后像我在示例中所做的那样将其导入到您的
AppModule
。如果失败了,请告诉我,并在您的问题中添加一个代码示例,这样我就可以检查是否存在一些错误或任何其他问题。
@NgModule({
    imports: [],
    declarations: [DatatableComponent],
    exports: [DatatableComponent]
})
export class DatatableModule{
}
@NgModule({
    imports: [DatatableModule],
    declarations: [],
    exports: []
})
export class MyCurrentViewModule{
}
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { DatatableComponent } from './datatable.component';

@NgModule({
    imports: [
        CommonModule
    ],
    declarations: [DatatableComponent],
    exports: [DatatableComponent]
})
export class DatatableModule{
}