我有一个明确的组件正在尝试引用,并且不断收到这个疯狂的错误。我已经正确设置了选择器以及相应的HTML。由于某些原因,即使我在模块中声明了该组件,我的应用也无法加载,并且抱怨该组件不存在。我在角度4。
ERROR Error: Uncaught (in promise): Error: Template parse errors:
Can't bind to 'data' since it isn't a known property of 'ng2-dual-list-box'.
1. If 'ng2-dual-list-box' is an Angular component and it has 'data' input, then verify that it is part of this module.
2. If 'ng2-dual-list-box' 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. (" class="row">
<div class="col-md-8 col-md-offset-2">
<ng2-dual-list-box [ERROR ->][data]="items" valueField="id" textField="name"
[(ngModel)]="select"): ng:///SharedModule/ListboxModalComponent.html@27:33
'ng2-dual-list-box' is not a known element:
这是我的组成部分
import { Component, Input, Output, EventEmitter, OnInit, forwardRef } from '@angular/core';
import { FormGroup, FormBuilder, FormControl, NG_VALUE_ACCESSOR, ControlValueAccessor } from '@angular/forms';
import 'rxjs/add/operator/debounceTime';
import 'rxjs/add/operator/distinctUntilChanged';
import 'rxjs/add/operator/map';
const intersectionwith = require('../../../../node_modules/lodash.intersectionwith');
const differenceWith = require('../../../../node_modules/lodash.differencewith');
import { IItemsMovedEvent, IListBoxItem } from '../dual listbox models';
@Component({
selector: 'ng2-dual-list-box',
templateUrl: './dual-list-box.component.html',
styleUrls: ['./dual-list-box.component.css'],
providers: [{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => DualListBoxComponent),
multi: true
}]
})
export class DualListBoxComponent implements OnInit, ControlValueAccessor {
// field to use for value of option
@Input() valueField = 'id';
// field to use for displaying option text
@Input() set textField(fields: any) {
if (Array.isArray(fields)) {
this._textField = (fields.length > 0) ? fields : ['name'];
} else {
this._textField = (fields) ? [fields] : ['name'];
}
};
@Input() separator = ' - ';
// array of items to display in left box
@Input() set data(items: Array<{}>) {
this.availableItems = [...(items || []).map((item: {}, index: number) => {
let fields = this._textField.map((field) => {
return item[field];
}).filter((data) => data != undefined);
return ({
value: item[this.valueField].toString(),
text: fields.join(this.separator)
});
}).filter((data) => data != undefined)];
};
array of items to display in right box
}
这是我的HTML
<div class="row">
<div class="col-md-8 col-md-offset-2">
<ng2-dual-list-box [data]="items" valueField="id" textField="name"
[(ngModel)]="selected"
(onAvailableItemSelected)="log($event)"
(onSelectedItemsSelected)="log($event)"
(onItemsMoved)="log($event)"></ng2-dual-list-box>
</div>
</div>
这是我的模块
import { DualListBoxComponent } from '../shared/profile listbox/dual-list-box.component';
@NgModule({
declarations: [
DualListBoxComponent
],
imports: [
],
providers: [
DualListBoxComponent
],
entryComponents: [
DualListBoxComponent],
})
export class ResearchModule { }