Answer the question
In order to leave comments, you need to log in
Why does Angular 4 say it doesn't know the component attribute even though it's specified?
persons.component.ts
import { Component, OnInit, Input } from '@angular/core';
import { Observable } from "rxjs/Observable";
import { IPerson } from "../../share/iperson";
@Component({
selector: 'app-persons',
templateUrl: './persons.component.html',
styleUrls: ['./persons.component.css']
})
export class PersonsComponent implements OnInit {
@Input() public persons: Observable<IPerson[]>;
constructor() { }
ngOnInit() {
}
}
<ul>
<li *ngFor="let person of persons | async">
<p><strong>{{person.GetShortName()}}</strong></p>
<p><em>{{person.GetAdditionalInfo()}}</em></p>
</li>
</ul>
<app-persons [persons]="students">
<p *ngIf="(students | async)?.length === 0">Список студентов пуст</p>
</app-persons>
import 'rxjs/add/operator/switchMap';
import { Component, OnInit } from '@angular/core';
import { StudentsService } from "./students.service";
import { ActivatedRoute, Router, ParamMap } from "@angular/router";
import { Observable } from "rxjs/Observable";
import { Student } from "../share/student";
@Component({
selector: 'app-students',
templateUrl: './students.component.html',
styleUrls: ['./students.component.css']
})
export class StudentsComponent implements OnInit {
students: Observable<Student[]>;
selectedStudentUid: string;
constructor(
private _service: StudentsService,
private _route: ActivatedRoute,
private _router: Router
) { }
ngOnInit() {
this.students = this._route.paramMap
.switchMap((params: ParamMap) => {
this.selectedStudentUid = params.get('id');
return this._service.GetAll();
});
}
}
ERROR Error: Uncaught (in promise): Error: Template parse errors:
Can't bind to 'persons' since it isn't a known property of 'app-persons'.
1. If 'app-persons' is an Angular component and it has 'persons' input, then verify that it is part of this module.
2. If 'app-persons' 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. ("<app-persons [ERROR ->][persons]="students">
<p *ngIf="(students | async)?.length === 0">Список студентов пуст</p>
</app"): ng:///StudentsModule/[email protected]:13
'app-persons' is not a known element:
1. If 'app-persons' is an Angular component, then verify that it is part of this module.
2. If 'app-persons' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("[ERROR ->]<app-persons [persons]="students">
<p *ngIf="(students | async)?.length === 0">Список студентов пу"): ng:///StudentsModule/[email protected]:0
Error: Template parse errors:
Can't bind to 'persons' since it isn't a known property of 'app-persons'.
1. If 'app-persons' is an Angular component and it has 'persons' input, then verify that it is part of this module.
2. If 'app-persons' 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. ("<app-persons [ERROR ->][persons]="students">
<p *ngIf="(students | async)?.length === 0">Список студентов пуст</p>
</app"): ng:///StudentsModule/[email protected]:13
'app-persons' is not a known element:
1. If 'app-persons' is an Angular component, then verify that it is part of this module.
2. If 'app-persons' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("[ERROR ->]<app-persons [persons]="students">
<p *ngIf="(students | async)?.length === 0">Список студентов пу"): ng:///StudentsModule/[email protected]:0...
Answer the question
In order to leave comments, you need to log in
I found the answer, the problem is not in the attribute, but in the fact that Angular was not compiled with this component at all, it turns out that the component can only be placed in one module, in principle, and if you need to use one component in different ones, then you need to move it to your own module, and then connect in those where it will be used.
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { PersonsComponent } from "./persons.component";
@NgModule({
imports: [
CommonModule
],
declarations: [
PersonsComponent
],
exports: [
CommonModule, PersonsComponent
]
})
export class PersonsModule { }
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question