【发布时间】:2016-11-16 16:21:36
【问题描述】:
我正在尝试使用 ionic 2 学习 ag2 并尝试最简单的事情。
我正在尝试在我的 ionic 2 应用中导入平台并获取必要的详细信息。
我关注了http://ionicframework.com/docs/v2/api/platform/Platform/
从 'ionic-angular' 导入 {Platform};
@Component({...})
export MyPage {
constructor(platform: Platform) {
this.platform = platform;
}
}
我的代码 -
import {Component} from '@angular/core';
import {Platform} from 'ionic-angular';
@Component({
templateUrl: 'build/pages/items-map/items-map.html'
})
export class ItemsMap {
constructor(platform: Platform) {
this.platform = platform;
}
btainNetworkConnection() {
this.platform.ready().then(() => {
this.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('Connection type: ' + states[this.networkState]);
});
}
}
现在我正在尝试通过 gulp build 构建代码库并获得以下输出 -
[00:06:26] Using gulpfile ~/Documents/Projects/Ionic2_1/MyIonic2Project/gulpfile.js
[00:06:26] Starting 'clean'...
[00:06:26] Finished 'clean' after 14 ms
[00:06:26] Starting 'build'...
[00:06:26] Starting 'sass'...
[00:06:26] Starting 'html'...
[00:06:26] Starting 'fonts'...
[00:06:26] Starting 'scripts'...
[00:06:26] Finished 'html' after 45 ms
[00:06:26] Finished 'scripts' after 43 ms
[00:06:26] Finished 'fonts' after 48 ms
[00:06:26] Finished 'sass' after 637 ms
TypeScript error: /Users/kray/Documents/Projects/Ionic2_1/MyIonic2Project/app/pages/item-map/items-map.ts(10,12): Error TS2339: Property 'platform' does not exist on type 'ItemsMap'.
[00:06:28] Finished 'build' after 2.28 s
我感觉我在这里缺少一些我不确定的基本内容。
我还检查了 node_modules 中与平台相关的打字稿文件,它们存在。快照 -
【问题讨论】:
标签: angularjs cordova angular ionic2