Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

667
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda