本文介绍了在离子2视图中显示电池状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正试图在离子视图中显示电池状态。我有显示网络连接解决方案。但无法显示电池状态,我已经安装了离子2电池状态插件
I am trying to display battery status in my ionic view. I got display network connection solution. but could not get to display battery status, I have installed ionic 2 battery status plugin
HTML
<h2>Battery status: {{status?.level}}</h2>
<h2>Battery is plugged:{{status?.isPlugged}}</h2>
TypeScript
status:any;
constructor(public alert:AlertController, public platform: Platform) {
this.platform.ready().then(()=>{
let subscription = BatteryStatus.onChange().subscribe( (status) => {
console.log(status.level, status.isPlugged);
this.status=status.level;
});
});
}
你可以从下面的bitbucket git克隆
You can clone from the below bitbucket git
$ git clone https://bitbucket.org/maniselvam/ionic2battery.git
推荐答案
在TS文件中导入电池状态。
Import the Battery Status on your TS file.
import { BatteryStatus } from 'ionic-native';
声明电池状态变量
Level:any = 0;
初始化插件
let subscription = BatteryStatus.onChange().subscribe(
(status) => {
this.Level = status.level;
console.log(status.level, status.isPlugged);
}
);
HTML
<h1>Battery Level: {{Level}}</h1>
这篇关于在离子2视图中显示电池状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!