angular - Ionic 2 Cordova network information plugin reference error -


i've installed network information plugin per tutorial ionic 2 app:

ionic 2 | how work cordova plugins

however typescript won't compile because can't find reference "connection" in states array lines. idea how write import statement per platform, page etc?

my class:

import {navcontroller, navparams} 'ionic-framework/ionic'; import {page, viewcontroller, platform, alert, modal, events} 'ionic-framework/ionic'; import {forwardref} 'angular2/core'; import {oninit} 'angular2/core'; import {injectable} 'angular2/core'; import {todosservice} '../../services/todosservice'; import {mytodositem} '../../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]);       });   } ..  } 

error is:
cannot find name 'connection'.

note:plugins not necessarily/always work in browser, therefore use real device or emulator.

to fix typescript errors:

  1. create folder called typings in /app
  2. download file folder: phonegaptypings here
  3. create file in folder e.g. ngcordova.d.ts code:

    interface window { plugins: any; }

then modify tsconfig.json files property:

  "files": [     "app/app.ts",     "app/typings/ngcordova.d.ts",     "app/typings/phonegap.d.ts"   ] 

now, typescript shouldn't complain, it'll build importantly: test on real device or emulator, not browser.

this worked me.


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -