Can't resolve parameters for a component from inside an injectable

257 views Asked by At

I'm trying to import a component into my injectable service, but it seems that I'm doing something wrong. This happens for other pages in similar situations as well. The current situation seems to happen because the LoginPage that I'm trying to import into SessionService requires SessionService, which smells of an infinite loop somewhere. Any ideas on how I should resolve it other than not including the page component in the injectable SessionService?

My current architecture is built so that I need to redirect to login page if session does not exist. Ionic NavController requires a page component for pushing onto navigation stack. Alternate ways of solving the redirection problem are welcome, but I would also like to understand why this is happening.

Uncaught Error: Can't resolve all parameters for LoginPage: (?, ContentService).

session.service.ts

@Injectable()
export class SessionService {
    constructor(private content: ContentService) {}
}

login.page.ts

@Component({
  templateUrl: './login.page.html'
})
export class LoginPage {
  constructor(public session: SessionService,
              public content: ContentService) {
  }

and for those who requested it, content.service.ts

@Injectable()
export class ContentService {
  constructor(private authHttp: AuthHttp) {
  }
}

app.module.ts

@NgModule({
  declarations: [
    LoginPage
  ],
  entryComponents: [
    LoginPage
  ],
  providers: [
    SessionService,
    ContentService
  ]
})
export class AppModule {
}

I'm using Angular 2.2.1 with Ionic 2.0.0-rc.4.

1

There are 1 answers

1
Ram_T On

content.service.ts

@Injectable()
export class ContentService {...}

Add this also like SessionService