Dav*_*ave 2 reference cordova-plugins ionic2 angular
我已根据本教程将网络信息插件安装到我的Ionic 2应用程序中:
但是,TypeScript无法编译,因为它无法在状态数组行中找到"连接"的引用.知道如何根据Platform,Page等为它编写import语句吗?
我的课:
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]);
});
}
..
}
Run Code Online (Sandbox Code Playgroud)
错误是:
找不到名称'连接'.
注意:插件不一定/始终在浏览器中工作,因此使用真实设备或模拟器.
要修复TypeScript错误:
使用以下代码在文件夹中创建另一个文件,例如ngcordova.d.ts:
界面窗口{plugins:any; }
然后修改你的tsconfig.json files属性:
"files": [
"app/app.ts",
"app/typings/ngcordova.d.ts",
"app/typings/phonegap.d.ts"
]
Run Code Online (Sandbox Code Playgroud)
现在,TypeScript不应该抱怨,它将构建但重要的是:在REAL设备或模拟器上测试,而不是浏览器.
这对我有用.
| 归档时间: |
|
| 查看次数: |
4293 次 |
| 最近记录: |