0
votes

here is my library service:

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

@Injectable({ providedIn: 'root' })

export class SharedService {

    name: string;

    constructor(name) { 
        this.name = name;
    }

}

when i do the build like : ng build getting error as :

Compiling TypeScript sources through ngc
Warning: Can't resolve all parameters for SharedService in C:/722333/Tutorials/my-workspace/projects/ibo-shared-lib/src/lib/services/shared.service.ts: (?). This will become an error in Angular v6.x
Warning: Can't resolve all parameters for SharedService in C:/722333/Tutorials/my-workspace/projects/ibo-shared-lib/src/lib/services/shared.service.ts: (?). This will become an error in Angular v6.x
ERROR: Can't resolve all parameters for SharedService in C:/722333/Tutorials/my-workspace/projects/ibo-shared-lib/src/lib/services/shared.service.ts: (?).

how to fix this? what is the correct way to handle this? thanks in advance.

1
Try constructor(name: string)?Mridul
@RamilAliyev - there is no solution mentioned thereuser2024080
@Mridul - no luckuser2024080
@user2024080, check this looks similar.Mridul

1 Answers

2
votes

you will have to use @inject in your constructor like below

export class SharedService {

name: string;

constructor(@inject('name') name) { 
    this.name = name;
}

}

but then you will have to provide a dependency provider with the 'name' in your module as per https://angular.io/guide/dependency-injection-providers (useValue / useExisting kind of injection)