模板网组件+离子天然健康+电容器

问题描述 投票:0回答:1

我正在尝试在模板应用程序中使用本地健康工具包。但是健康永远是不确定的。

我正在将电容器和stenciljs与本地Web组件一起使用。

消息:TypeError:无法读取未定义的属性'isAvailable'

还有其他人遇到过这个问题吗?

import { Component, State, h } from "@stencil/core";
import { Health } from "@ionic-native/health/ngx";

@Component({
  tag: "list-stats"
})
export class ListStats {
  private health: Health;

  componentDidLoad() {

    this.health
      .isAvailable()
      .then((available: boolean) => {
        console.log(available);
        this.health
          .requestAuthorization([
            "distance",
            "nutrition", //read and write permissions
            {
              read: ["steps"], //read only permission
              write: ["height", "weight"] //write only permission
            }
          ])
          .then(res => console.log(res))
          .catch(e => console.log(e));
      })
      .catch(e => console.log(e));
  }



  render() {
    return [
     <ion-label>
      <p>Steps</p>
     </ion-label>
    ];
  }
}
ionic-framework health-kit capacitor
1个回答
0
投票

您需要Inject Health类,因为它是单身。只需添加一个构造器方法并注入Health类,如下所示。

export class ListStats {
constructor(private health: Health) { }
...
}
© www.soinside.com 2019 - 2024. All rights reserved.