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

665
Visualizações
Angular 13 - Assertion Error on importing own package

maybe someone can help me: I have created my first Angular package. The package itself has to provide different services to make HTTP requests to a server and return the results.

However, when importing the service, the web page stops rendering and I get an error message:

core.mjs:6484 ERROR Error: ASSERTION ERROR: token must be defined [Expected=> null != undefined <=Actual]
    at throwError (core.mjs:326)
    at assertDefined (core.mjs:322)
    at bloomHashBitOrFactory (core.mjs:3591)
    at getOrCreateInjectable (core.mjs:3379)
    at Module.ɵɵdirectiveInject (core.mjs:14392)
    at NodeInjectorFactory.AppComponent_Factory [as factory] (app.component.ts:10)
    at getNodeInjectable (core.mjs:3556)
    at instantiateRootComponent (core.mjs:10159)
    at createRootComponent (core.mjs:12259)
    at ComponentFactory.create (core.mjs:21580)

My Service:

// imports ...

/**
 * DoctorService
 */
@Injectable({
  providedIn: "root"
})
export class DoctorService {

  constructor(private readonly httpClient: HttpClient) { }

  /**
   * Returns a doctor by a given uuid.
   *
   * @param uuid
   * @return Promise<Doctor>
   */
  public async getDoctorByUUID(uuid: string): Promise<Doctor> {
    const uuidRegExp = new RegExp(/[0-9a-f]{8}\b-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-\b[0-9a-f]{12}/);

    if (!uuidRegExp.test(uuid)) {
      console.error("UUID does not have a valid format. It needs to be in a 8-4-4-4-12 digit pattern.")
      return new Promise<Doctor>(() => {
        return [];
      });
    }

    const httpParams: HttpParams = new HttpParams();
    httpParams.set("module", "mydoc");
    httpParams.set("sektion", "show_doctor");
    httpParams.set("uuid", uuid);
    httpParams.set("return", "json");

    const request = this.httpClient.get<Doctor>(API_BASE_URL, { params: httpParams });

    return firstValueFrom(request);
  }
}

Component which uses the Service:

import {Component} from '@angular/core';
import {DoctorService} from "my-doc-util/src/lib/services/doctor-service/doctor.service";

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'angular-testing';
  
  constructor(private readonly doctorService: DoctorService) {
  }
}

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I have experienced the same exact error (angular 11)

I don't know if it's the same reason but in my case, it turned out that the component had an uninitialized input.

about 4 years ago · Juan Pablo Isaza 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