钢板网组件+离子天然养护+电容器

时间:2019-10-26 12:14:07

标签: ionic-framework healthkit capacitor

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

我正在将电容器和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>
    ];
  }
}

1 个答案:

答案 0 :(得分:0)

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

export class ListStats {
constructor(private health: Health) { }
...
}