I have an Angular 8 app that consumes a Service from a custom library I created.
The Service makes a HTTP call, so it has a dependency for an instance of the HttpClient in its constructor as follows:
import { Injectable } from '@angular/core';
import { Observable, of } from 'rxjs';
import { HttpClient } from '@angular/common/http';
import { User } from '../../models/user.model';
import { GetLoggedInUserInfo } from '../../models/get-logged-in-user-info';
@Injectable({
providedIn: 'root',
})
export class AuthService {
constructor(private http: HttpClient) {}
getLoggedInUser = ({
apiUrl,
apiContextRoot,
}: GetLoggedInUserInfo): Observable<User> => {
const url = `${apiUrl}${apiContextRoot}/login`;
return this.http.get<User>(url).pipe(
);
}
};
}
The problem occurs when I invoke the getLoggedInUser() method of this service from the client app that custom installed the library via "npm install".
It seems that the dependency is not being fulfilled for the service in the custom library, which I thought would occur automatically.
main.ts:12 Error: inject() must be called from an injection context
at injectInjectorOnly (core.js:728)
at ɵɵinject (core.js:744)
at AuthService_Factory (gulfstream-common.js:493)
at _callFactory (core.js:30485)
at _createProviderInstance (core.js:30428)
at resolveNgModuleDep (core.js:30387)
at NgModuleRef_.get (core.js:31577)
at resolveDep (core.js:32142)
at createClass (core.js:31988)
at createDirectiveInstance (core.js:31806)
Any ideas?
Thanks
AuthServiceis used?