1

我正在尝试将一个组件导入到我的可注入服务中,但似乎我做错了什么。类似情况下的其他页面也会发生这种情况。目前的情况似乎发生了,因为我试图导入 SessionService 的 LoginPage 需要 SessionService,它在某处闻起来有无限循环的味道。除了在可注入的 SessionService 中不包括页面组件之外,我应该如何解决它的任何想法?

我当前的架构是构建的,因此如果会话不存在,我需要重定向到登录页面。Ionic NavController 需要一个页面组件来推送到导航堆栈。欢迎使用其他解决重定向问题的方法,但我也想了解为什么会这样。

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

会话服务.ts

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

登录页面.ts

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

对于那些要求它的人,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 {
}

我将 Angular 2.2.1 与 Ionic 2.0.0-rc.4 一起使用。

4

1 回答 1

0

内容服务.ts

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

添加这个也喜欢SessionService

于 2016-12-22T10:53:10.567 回答