我正在尝试在项目的其他模块中使用子组件,但是由于它不是'or-app-wysiwyg'的已知属性,因此我收到错误消息'Ca n't bind to'message'。我看不到导入的任何问题,并且检查了是否正确添加了Forms模块。我相信问题与选择器有关,但到目前为止,我尝试过的所有操作都无法摆脱错误。
Wysiwyg.Component.ts
import { Component, OnInit} from '@angular/core';
import * as ClassicEditor from '@ckeditor/ckeditor5-build-classic';
@Component({
selector: 'or-app-wysiwyg',
templateUrl: './wysiwyg.component.html',
styleUrls: ['./wysiwyg.component.scss']
})
export class WysiwygComponent implements OnInit {
public Editor = ClassicEditor;
message = '';
constructor() { }
ngOnInit() {
}
}
Wysiwyg.Component.html
<ckeditor [(ngModel)]="message" [editor]="Editor"></ckeditor>
Notes.Component.ts
import { Component, OnInit, ChangeDetectorRef, Input } from '@angular/core';
import * as ClassicEditor from '@ckeditor/ckeditor5-build-classic';
import { Note } from '../../../../../core/src/models/note';
import { NoteOutgoing } from 'projects/core/src/models/noteOutgoing';
import { AuthService } from 'core';
import { NotesService } from 'projects/core/src/services/note.service';
@Component({
selector: 'app-notes',
templateUrl: './notes.component.html',
styleUrls: ['./notes.component.scss'],
})
export class NotesComponent implements OnInit {
@Input() message: any;
public Editor = ClassicEditor;
notes: Note[] = [];
noteOutgoing: NoteOutgoing = {message: ''};
constructor(private noteService: NotesService, private authService: AuthService,
private cdr: ChangeDetectorRef) {}
ngOnInit() {
this.getNotes();
}
getNotes() {
this.noteService.getNotesFromDB().subscribe(result => {
this.notes = result;
this.cdr.detectChanges();
}, error => console.error(error));
}
addNote() {
const name = this.authService.getUser().firstName + ' ' + this.authService.getUser().lastName;
const note: Note = {name, message: this.noteOutgoing.message, date: 'date', tags: 'tag'};
this.notes.push(note);
console.log(this.notes);
this.noteService.addNoteToDB(this.noteOutgoing).subscribe(() => {
}, error => console.error(error));
this.noteOutgoing.message = '';
}
}
Note.Module.ts
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { NotesComponent } from './notes.component';
import { CKEditorModule } from '@ckeditor/ckeditor5-angular';
import { FormsModule } from '@angular/forms';
import { WysiwygComponent } from 'projects/core/src/components/wysiwyg/wysiwyg.component';
@NgModule({
imports: [
CommonModule,
CKEditorModule,
FormsModule
],
declarations: [NotesComponent, WysiwygComponent]
})
export class NotesModule {}
您的错误消息是这样:
'无法绑定到'消息',因为它不是'or-app-wysiwyg'的已知属性
您尚未发布有问题的代码,但是错误消息表明您正在尝试绑定到元素message
上的or-app-wysiwyg
属性,该属性看起来像这样:
<or-app-wysiwyg [message]="message">
</or-app-wysiwyg>
为了执行此操作,您需要将message
属性指定为@Input()
属性。
Wysiwyg.component.ts
export class WysiwygComponent implements OnInit {
public Editor = ClassicEditor;
@Input() message: string;
}