0

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.

6
  • Please to look throught github.com/ng-packagr/ng-packagr/issues/377 Commented Feb 13, 2020 at 9:57
  • Try constructor(name: string)? Commented Feb 13, 2020 at 9:58
  • @RamilAliyev - there is no solution mentioned there Commented Feb 13, 2020 at 10:04
  • @Mridul - no luck Commented Feb 13, 2020 at 10:04
  • @user2024080, check this looks similar. Commented Feb 13, 2020 at 10:06

1 Answer 1

2

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)

Sign up to request clarification or add additional context in comments.

1 Comment

You saved my life. from the morning i was in trouble.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.