Reputation: 308
I am attempting to use a a sub component in a different module in my project but I am receiving the error 'Can't bind to 'message' since it isn't a known property of 'or-app-wysiwyg'. I can't see any issues with my imports, and I have checked that my the forms module has been added correctly. I believe the issue is to do with the selector but everything I have tried so far does not get rid of the error.
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 {}
Notes.Component.html
<or-app-wysiwyg [message]="message"></or-app-wysiwyg>
<button type="button" (click)="addNote()" class="btn btn-
default">Save</button>
<div class= "card m-3" *ngFor= "let note of notes">
Name: {{note.name}} <br> Note: {{note.message}} <br> Date: {{note.date}} <br>
Tags: {{note.tags}}
</div>
Upvotes: 0
Views: 96
Reputation: 13515
Your error message is this:
'Can't bind to 'message' since it isn't a known property of 'or-app-wysiwyg'
You've not posted the offending code, but the error message suggests you are trying to bind to the message
property on the element or-app-wysiwyg
, which would look something like this:
<or-app-wysiwyg [message]="message">
</or-app-wysiwyg>
In order to do this, you need to specify the message
property as an @Input()
property.
Wysiwyg.component.ts
export class WysiwygComponent implements OnInit {
public Editor = ClassicEditor;
@Input() message: string;
}
Upvotes: 1