Angular Service with error

Asked

Viewed 61 times

0

The error is after compiling:

ERROR in src/app/core/services/service-principal.service.ts:25:12 - error NG2003: No suitable Injection token for Parameter 'base' of class 'Serviceprincipalservice'. Found string public base: string

Class

 import { CrudOperations } from './crudoperations.interface';

    import { HttpClient } from '@angular/common/http';

    import {

      ActivatedRoute,

      Router

    } from '@angular/router';

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

    import { CLINICA_MEDICA_API } from './clinicamedica.api';

    import pickBy from 'lodash/pickBy';

    import isArray from 'lodash/isArray';

    import isEmpty from 'lodash/isEmpty';

    import isUndefined from 'lodash/isUndefined';

    import isNull from 'lodash/isNull';

    import trim from 'lodash/trim';

    @Injectable({

      providedIn: 'root'

    })

    export class ServicePrincipalService<T, ID> implements CrudOperations<T, ID> {

      constructor(

        public httpClient: HttpClient,

        public activatedRoute: ActivatedRoute,

        public router: Router,

        public base: string

      ) {}

      public incluir(t: T) {

        return this.httpClient.post(`${CLINICA_MEDICA_API}` + this.base + '/incluir', t);

      }

      public alterar(t: T) {

        return this.httpClient.put(`${CLINICA_MEDICA_API}` + this.base + '/alterar', t);

      }

      public excluir(id: ID) {

        return this.httpClient.delete(`${CLINICA_MEDICA_API}` + this.base + '/excluir/' + id);

      }

      public pesquisar(p: T) {

        const params: any = this.removerUndefinedEmptyNull(p);

        this.updateURLComParametrosDePesquisa(p);

        return this.httpClient.get(`${CLINICA_MEDICA_API}` + this.base + '/pesquisar', { params });

      }

      public buscar(id: ID) {

        return this.httpClient.get(`${CLINICA_MEDICA_API}` + this.base + '/buscar/' + id);

      }

      private removerUndefinedEmptyNull(parameters: any) {

        const res = pickBy(parameters,

          // tslint:disable-next-line:only-arrow-functions

          function(value: any) {

              let definido: boolean;

              if (isArray(value)) {

                definido = !isEmpty(value);

              } else {

                definido = !isUndefined(value) && !isNull(value) && !isEmpty(trim(value));

              }

              return definido;

          }

        );

        return res;

      }

      private updateURLComParametrosDePesquisa(parametros: any) {

        this.router.navigate([], { relativeTo: this.activatedRoute, queryParams: parametros });

      }

    }
  • what is this base? It does not know how to inject this string

  • she’d better be on the enviroment

  • The basis is the address the client will access the server endpoint. Examples: 1) if I am on the client screen and n server endpoint is client, The angle passes this as parameter, for the service to be accessed. 2) if I am on the sell screen and n server the endpoint is sale, The angle passes this as parameter, for the service to be accessed.

  • how are you injecting this string? The angler won’t find it out of nowhere

  • Then I changed string to String and it worked.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.