Невозможно привязать к свойству, так как оно не является известным свойством селектора - PullRequest
0 голосов
/ 09 марта 2020

Я пытаюсь использовать субкомпонент в другом модуле в моем проекте, но я получаю сообщение об ошибке «Невозможно привязать к« сообщению », так как оно не является известным свойством« or-app-wysiwyg ». Я не вижу проблем с импортом, и я проверил, что мой модуль форм был добавлен правильно. Я считаю, что проблема связана с селектором, но все, что я пробовал до сих пор, не избавляет от ошибки.

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 {}

Примечания. Компонент. 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>

1 Ответ

1 голос
/ 09 марта 2020

Ваше сообщение об ошибке:

'Невозможно привязать к' сообщению ', поскольку оно не является известным свойством' 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;
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...