【发布时间】:2016-06-09 16:52:23
【问题描述】:
我已按照本教程将网络信息插件安装到我的 Ionic 2 应用程序中:
Ionic 2 | How to Work With Cordova Plugins
但是,TypeScript 无法编译,因为它在 states 数组行中找不到“Connection”的引用。知道如何根据平台、页面等为其编写导入语句吗?
我的班级:
import {NavController, NavParams} from 'ionic-framework/ionic';
import {Page, ViewController, Platform, Alert, Modal, Events} from 'ionic-framework/ionic';
import {forwardRef} from 'angular2/core';
import {OnInit} from 'angular2/core';
import {Injectable} from 'angular2/core';
import {TodosService} from '../../services/TodosService';
import {MyTodosItem} from '../../pages/my-todos-item/my-todos-item';
@Page({
templateUrl: 'build/pages/my-todos/my-todos.html'
})
class TodayPage {
constructor(
private platform: Platform,
private nav: NavController,
private _events: Events,
private _todosService: TodosService) {
this._platform = platform;
this._isAndroid = platform.is('android');
}
ngOnInit() {
this.getItems();
this._events.subscribe('item:updated', () => {
this.getItems();
});
this.checkNetwork();
}
checkNetwork() {
this._platform.ready().then(() => {
var networkState = navigator.connection.type;
var states = {};
states[Connection.UNKNOWN] = 'Unknown connection';
states[Connection.ETHERNET] = 'Ethernet connection';
states[Connection.WIFI] = 'WiFi connection';
states[Connection.CELL_2G] = 'Cell 2G connection';
states[Connection.CELL_3G] = 'Cell 3G connection';
states[Connection.CELL_4G] = 'Cell 4G connection';
states[Connection.CELL] = 'Cell generic connection';
states[Connection.NONE] = 'No network connection';
alert(states[networkState]);
});
}
..
}
错误是:
找不到名称“连接”。
【问题讨论】:
标签: reference angular cordova-plugins ionic2