Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

199
Views
Angular 4 No se puede vincular a <property> ya que no es una propiedad conocida de <component>

Estoy tratando de crear mi propia directiva en Angular 4. Pero recibí este error al vincular la propiedad de la clase en la plantilla del componente.

Error de la consola:

 Unhandled Promise rejection: Template parse errors: Can't bind to 'data' since it isn't a known property of 'tree'. ("<tree [ERROR ->][data]="data"></tree>"):

Mi vista de árbol-component.ts:

 @Component({ selector: 'app-tree-view', template: '<tree [data]="data"></tree>' }) export class TreeViewComponent implements OnInit { @Input() data: any[]; constructor() { this.data = [ { label: 'a1', subs: [ { label: 'a11', subs: [ { label: 'a111', subs: [ { label: 'a1111' }, { label: 'a1112' } ] }, { label: 'a112' } ] }, { label: 'a12', } ] } ]; } ngOnInit() { } }

Aquí está mi archivo de script completo: https://pastebin.com/hDyX2Kjj

¿Hay alguien que sepa sobre esto? TiA

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Cada componente, directiva y tubería debe registrarse en @NgModule()

 @NgModule({ declarations: [TreeViewComponent] }) export class AppModule {}

Para más detalles ver

  • https://angular.io/api/core/NgModule
  • https://angular.io/guide/ngmodules
  • https://angular.io/guide/ngmodule-api
over 4 years ago · Santiago Trujillo Report

0

Tengo el mismo error cuando ejecuto la prueba para ParentComponent. Dentro estaba el componente ChildComponent con la propiedad @Input: string;. Ambos componentes también se declararon dentro de app.module.ts.

He arreglado esto así (archivo de prueba del componente principal):

 beforeEach(async(() => { TestBed.configureTestingModule({ declarations: [ParentComponent, ChildComponent]// added child component declaration here }) .compileComponents(); }));
over 4 years ago · Santiago Trujillo Report

0

Como señaló The Aelfinn , si está utilizando su Componente a través de Módulos, necesita exportarlo. ¡ PERO no debe importarlo, exportarlo y declararlo en el Módulo en el que desea usarlo, ya que no forma parte de este Módulo!
Así que suponga que tiene un TreeViewStuffModule que declara el TreeViewComponent y un DoSomethingWithTreeViewModule donde se usa el TreeViewComponent, sus declaraciones serían las siguientes:

 @NgModule({ declarations: [ TreeViewComponent ], exports: [ TreeViewComponent ] }) export class TreeViewStuffModule { } @NgModule({ imports: [ TreeViewStuffModule ] }) export class DoSomethingWithTreeViewModule
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!