Ionic 2:将配置属性移动到引导程序中

时间:2016-06-08 06:34:24

标签: ionic-framework angular ionic2

在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')
 );

在新版本之后,配置必须进入引导程序,因此在我的js中实现了以下内容:

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

export class LoginPage {

...

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

其中引发了我的错误:

enter image description here

使用

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

ionicBootstrap(LoginPage, [httpService]);

给出相同的错误结果。

1 个答案:

答案 0 :(得分:1)

ionicBootstrap必须仅用于您之前的@App,而不能用于之前的@Page,请注明httpService,而不是LoginPage

在您的LoginPage中离开提供者注册。另外,请注意您的命名约定,它看起来不正确,您使用的服务及其实例名称相同。它应该是这样的:

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

      constructor ( private httpService : HttpService) {}

}

也是,它是beta 8,而不是RC