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

664
Views
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 answers
Answer question

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 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!