Ionic 2:将配置属性移动到 bootstrap

Ionic 2 : Moving config properties into the bootstrap

在 beta.8 版本之前,我有一个工作服务作为我的 HTTP 服务。

@Page({
  templateUrl: 'build/pages/log-in/log-in.html',
  providers: [httpService]
})

...

this.httpService.testService("VariablesToPass").subscribe(
    data => {this.results = data.results; console.log(data);},
    //err => this.logError(err),
    err => console.log(err),
    () => console.log('Invoked Login Service Complete')
 );

在新版本之后,配置必须移动到 bootstrap,因此在我的 js 中我实现了以下内容:

@Component({
  templateUrl: 'build/pages/log-in/log-in.html'
})

export class LoginPage {

...

}
ionicBootstrap(LoginPage, [httpService], {});

其中抛出如下错误:

使用

ionicBootstrap(LoginPage, [httpService], {});

ionicBootstrap(LoginPage, [httpService]);

给出相同的错误结果。

ionicBootstrap 必须只用在你的前 @App 中,不能在前 @Page 中使用,在那里插入 httpService,而不是 LoginPage

在您的登录页面中留下提供商注册。另外,请注意您的命名约定,它看起来不对,您对服务及其实例使用相同的名称。应该是这样的:

    @Component({
      templateUrl: 'build/pages/log-in/log-in.html',
      providers: [HttpService]
    })
    class LoginPage {

      constructor ( private httpService : HttpService) {}

}

此外,它是 beta 8,不是 RC