I upgraded my Angular2 project which was working fine from Beta .21 to beta .25.5. I have fixed all error so that there are no errors when using AOT or non-AOT (e.g. ng serve)
I now get this error on many of my services at runtime when the browser loads and it affects ALL the parameter services for that file.
Can't resolve all parameters for *servicename*: (?)
First I deleted the barrel I was using and checked circular dependancies.
I then moved them all into the Providers array in App.module and checked that all services have @Injectable(). the only way to get rid of the error was to use the Inject() method, eg:
import { Injectable, Optional, SkipSelf, Inject } from '@angular/core';
import { Subject } from 'rxjs/Subject';
export interface SpinnerState {
show: boolean;
}
@Injectable()
export class SpinnerService {
private spinnerSubject = new Subject<SpinnerState>();
spinnerState = this.spinnerSubject.asObservable();
constructor( @Optional() @SkipSelf() @Inject(SpinnerService) prior: SpinnerService) {
This fixed the errors but then I got this error on a 3rd party library. How can I debug this to work out the root cause of the problem?
Thanks
"nativeError : Error: Can't resolve all parameters for Logger: (?). at SyntaxError.BaseError [as constructor] (http://localhost:4200/vendor.bundle.js:134335:27) [<r
"
This is how my App.Module looks:
providers: [
{
provide: AuthHttp,
useFactory: authHttpServiceFactory,
deps: [Http, RequestOptions],
},
[Logger],
LoggerService,
SpinnerService,
DataBreezeService,
ProfileService,
AuthService,
AuthGuardService,
CanDeactivateGuardService,
I also have these set:
{
"emitDecoratorMetadata": true,
"experimentalDecorators": true
}
(as mentioned, my project was working fine before the upgrade - I can't see anything obvious in the release notes).
UPDATE I kept commenting out services with issues and removing params from constructors and each time it just moves to the next service - ie. there is something wrong at a higher level here. Now I am also getting 404 errors on components too, eg.
I don't understand why - for example, the 404 Subscribe component is really simple: I even tried adding "moduleId: 'module.id', " but that made no difference:
import { Component } from '@angular/core';
@Component({
selector: 'app-subscribe',
templateUrl: './subscribe.component.html',
styleUrls: ['./subscribe.component.scss']
})
export class SubscribeComponent {
constructor() { }
}
GET http://localhost:4200/subscribe.component.html 404 (Not Found)
Logger
look like? - Günter ZöchbauerLogger
with an array[Logger],
? - should work fine, just curious - Günter Zöchbauer