Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

504
Visualizações
Can't construct a query for the property, since the query selector wasn't defined

Currently have this problem with a component in Angular 2 that exists of other components. The components of the 'main' component can exist multiple times in the hierarchy.

But i am getting this error: "Can't construct a query for the property "navComponent" of "SidenavLinkComponent" since the query selector wasn't defined"

SidenavLinkComponent:
@ContentChild(SidenavNavComponent) navComponent: SidenavNavComponent;

SidenavNavComponent:
@ContentChildren(SidenavLinkComponent) linkComponents: QueryList<SidenavLinkComponent>;

I have made this slim plunker, where the problem is shown: Plunker

I have no idea why it happens.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

It's because of a circular dependency between SidenavComponent and SidenavNavComponent. It can be resolved using forwardRef. Don't forget to import it as well:

import { forwardRef } from '@angular/core';

@ViewChild(forwardRef(() => SidenavNavComponent))
private navComponent: SidenavNavComponent;

Plunker example

over 4 years ago · Santiago Trujillo Relatório

0

I had this error when using an enum in a specfile.

app.component.ts

@Component({
  selector: 'mintplayer-ng-bootstrap-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss'],
})
export class AppComponent {
  title = 'ng-bootstrap-demo';
  colors = Color; // Comment out this line to make the unit tests succeed
}

app.component.spec.ts

describe('AppComponent', () => {
  let fixture: ComponentFixture<AppComponent>;

  beforeEach(async () => {
    await TestBed.configureTestingModule({
      declarations: [
        // Component to test
        AppComponent,
      ],
      imports: [
        RouterTestingModule
      ],
      // providers: [
      //   { provide: Color }
      // ]
    }).compileComponents();
  });

  it('should create the app', () => {
    fixture = TestBed.createComponent(AppComponent);
    fixture.detectChanges();

    const app = fixture.componentInstance;
    expect(app).toBeTruthy();
  });
});

enum Color {
  primary,
  secondary,
  success,
  danger,
  warning,
  info,
  light,
  dark,
  body,
  white,
  transparent
}

Don't know yet how to solve it, but I thought it might be interesting to point out since the error message is completely off...

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda