get router's IP Address in ionic2 - Non Native Plugin - ionic-framework

Plugin:
cordova plugin add cordova-plugin-networkinterface
Code:
networkinterface.getIpAddress((ip) => {
console.log(ip);
});
Error:
TypeError: Cannot read property 'getIPAddress' of undefined
Now here neither I have provide any provider nor any import, so how does it work in ionic 2 ?
It's not A native plugin. But this plugin is working in ionic 2 also according to this link
Package.json :
{
"name": "ionic-hello-world",
"author": "Ionic Framework",
"homepage": "http://ionicframework.com/",
"private": true,
"scripts": {
"clean": "ionic-app-scripts clean",
"build": "ionic-app-scripts build",
"ionic:build": "ionic-app-scripts build",
"ionic:serve": "ionic-app-scripts serve"
},
"dependencies": {
"#angular/common": "2.4.8",
"#angular/compiler": "2.4.8",
"#angular/compiler-cli": "2.4.8",
"#angular/core": "2.4.8",
"#angular/forms": "2.4.8",
"#angular/http": "2.4.8",
"#angular/platform-browser": "2.4.8",
"#angular/platform-browser-dynamic": "2.4.8",
"#angular/platform-server": "2.4.8",
"#ionic-native/core": "3.1.0",
"#ionic-native/in-app-browser": "^3.4.2",
"#ionic-native/network": "^3.4.2",
"#ionic-native/splash-screen": "3.1.0",
"#ionic-native/status-bar": "3.1.0",
"#ionic-native/toast": "^3.4.4",
"#ionic/app-scripts": "^1.2.2",
"#ionic/storage": "2.0.0",
"ionic-angular": "2.3.0",
"ionic-native": "^2.9.0",
"ionicons": "3.0.0",
"rxjs": "5.0.1",
"sw-toolbox": "3.4.0",
"zone.js": "0.7.2"
},
"devDependencies": {
"#ionic/app-scripts": "1.2.2",
"typescript": "2.0.9"
},
"cordovaPlugins": [
"cordova-plugin-whitelist",
"cordova-plugin-statusbar",
"cordova-plugin-console",
"cordova-plugin-device",
"cordova-plugin-splashscreen",
"ionic-plugin-keyboard"
],
"cordovaPlatforms": [],
"description": "Test"
}
Latest Code File :
declare var networkinterface: any;
#Component({
templateUrl: 'app.html'
})
export class MyApp {
public rootPage:any = HomePage;
constructor(private platform: Platform,private statusBar: StatusBar,private splashScreen: SplashScreen, private network: Network, private iab: InAppBrowser, private http: Http, private toast: Toast) {
platform.ready().then(() => {
networkinterface.getWiFiIPAddress((ip) => {
console.log(ip);
});
}

You have to use it like below after installing the non-native plugin.
This method (getIpAddress()) is deprecated and uses the
getWiFiIPAddress() method.
declare let networkinterface: any;
#Component({
...
})
export class TestPage {
...
getIpAddress() {
networkinterface.getWiFiIPAddress((ip) => {
console.log(ip);
});
}
}

You can try using external url:
async function getIP(){
const repsIP = await fetch('https://api.ipify.org/?format=json');
const data = await repsIP.json();
return data;
}
Wherever you want, call this function:
this.getIP().then(data => this.ipAddress = data.ip);

Related

I installed ngx echarts in an Angular 14 project but I get this error Generic type 'ɵɵDirectiveDeclaration' requires between 6 and 8 type arguments

After doing the install using
npm install echarts -S
npm install ngx-echarts -S
import { NgModule } from '#angular/core';
import { BrowserModule } from '#angular/platform-browser';
import { HttpClientModule } from '#angular/common/http';
import { MatFormFieldModule, MatIconModule, MatInputModule, MatMenuModule, MatSelectModule } from '#angular/material';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { BrowserAnimationsModule } from '#angular/platform-browser/animations';
import { DashboardComponent } from './pages/dashboard/dashboard.component';
import { PageHeaderComponent } from './components/page-header/page-header.component';
import { ChubbTableComponent } from './components/chubb-table/chubb-table.component';
import { StatusChipComponent } from './components/status-chip/status-chip.component';
import { NgxEchartsModule } from 'ngx-echarts';
#NgModule({
declarations: [
AppComponent,
DashboardComponent,
PageHeaderComponent,
ChubbTableComponent,
StatusChipComponent,
],
imports: [
BrowserModule,
HttpClientModule,
BrowserAnimationsModule,
AppRoutingModule,
MatInputModule,
MatFormFieldModule,
MatSelectModule,
MatIconModule,
MatMenuModule,
NgxEchartsModule.forRoot({
/**
* This will import all modules from echarts.
* If you only need custom modules,
* please refer to [Custom Build] section.
*/
echarts: () => import('echarts'), // or import('./path-to-my-custom-echarts')
})
],
exports: [
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
this is what my app.module.ts looks like. But I get this error below when serving.
{
"name": "modular-ui",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve --open",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test"
},
"private": true,
"dependencies": {
"#angular/animations": "^14.2.12",
"#angular/cdk": "^7.3.7",
"#angular/common": "^14.0.0",
"#angular/compiler": "^14.0.0",
"#angular/core": "^14.0.0",
"#angular/forms": "^14.0.0",
"#angular/material": "^7.3.7",
"#angular/platform-browser": "^14.0.0",
"#angular/platform-browser-dynamic": "^14.0.0",
"#angular/router": "^14.0.0",
"bootstrap": "^5.2.3",
"bootstrap-icons": "^1.10.3",
"clone-deep": "^4.0.1",
"echarts": "^5.4.1",
"material-components-web": "^14.0.0",
"ngx-echarts": "^15.0.1",
"rxjs": "~7.5.0",
"tslib": "^2.3.0",
"zone.js": "~0.11.4"
},
"devDependencies": {
"#angular-devkit/build-angular": "^14.0.4",
"#angular/cli": "~14.0.4",
"#angular/compiler-cli": "^14.0.0",
"#types/jasmine": "~4.0.0",
"jasmine-core": "~4.1.0",
"karma": "~6.3.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.2.0",
"karma-jasmine": "~5.0.0",
"karma-jasmine-html-reporter": "~1.7.0",
"typescript": "~4.7.2"
}
}
this is my package.json
Error: node_modules/ngx-echarts/lib/ngx-echarts.directive.d.ts:90:18 - error TS2707: Generic type 'ɵɵDirectiveDeclaration' requires between 6 and 8 type arguments.
90 static ɵdir: i0.ɵɵDirectiveDeclaration<NgxEchartsDirective, "echarts, [echarts]", ["echarts"], { "options": "options"; "theme": "theme"; "initOpts": "initOpts"; "merge": "merge"; "autoResize": "autoResize"; "loading": "loading"; "loadingType": "loadingType"; "loadingOpts": "loadingOpts"; }, { "chartInit": "chartInit"; "optionsError": "optionsError"; "chartClick": "chartClick"; "chartDblClick": "chartDblClick"; "chartMouseDown": "chartMouseDown"; "chartMouseMove": "chartMouseMove"; "chartMouseUp": "chartMouseUp"; "chartMouseOver": "chartMouseOver"; "chartMouseOut": "chartMouseOut"; "chartGlobalOut": "chartGlobalOut"; "chartContextMenu": "chartContextMenu"; "chartLegendSelectChanged": "chartLegendSelectChanged"; "chartLegendSelected": "chartLegendSelected"; "chartLegendUnselected": "chartLegendUnselected"; "chartLegendScroll": "chartLegendScroll"; "chartDataZoom": "chartDataZoom"; "chartDataRangeSelected": "chartDataRangeSelected"; "chartTimelineChanged": "chartTimelineChanged"; "chartTimelinePlayChanged": "chartTimelinePlayChanged"; "chartRestore": "chartRestore"; "chartDataViewChanged": "chartDataViewChanged"; "chartMagicTypeChanged": "chartMagicTypeChanged"; "chartPieSelectChanged": "chartPieSelectChanged"; "chartPieSelected": "chartPieSelected"; "chartPieUnselected": "chartPieUnselected"; "chartMapSelectChanged": "chartMapSelectChanged"; "chartMapSelected": "chartMapSelected"; "chartMapUnselected": "chartMapUnselected"; "chartAxisAreaSelected": "chartAxisAreaSelected"; "chartFocusNodeAdjacency": "chartFocusNodeAdjacency"; "chartUnfocusNodeAdjacency": "chartUnfocusNodeAdjacency"; "chartBrush": "chartBrush"; "chartBrushEnd": "chartBrushEnd"; "chartBrushSelected": "chartBrushSelected"; "chartRendered": "chartRendered"; "chartFinished": "chartFinished"; }, never, never, false, never>;
not sure what is wrong as I only followed the simple instructions

IONIC native plugin not working in IOINIC app

I have a problem with IONIC, whenever I import a native plugin the application stops working.
Here I add the package.json:
{
"name": "noticias",
"version": "0.0.1",
"author": "Ionic Framework",
"homepage": "https://ionicframework.com/",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"#angular/common": "~11.2.0",
"#angular/core": "~11.2.0",
"#angular/forms": "~11.2.0",
"#angular/platform-browser": "~11.2.0",
"#angular/platform-browser-dynamic": "~11.2.0",
"#angular/router": "~11.2.0",
"#capacitor/core": "2.4.7",
"#ionic-native/in-app-browser": "^5.31.1",
"#ionic-native/social-sharing": "^5.31.1",
"#ionic/angular": "^5.5.2",
"cordova-plugin-inappbrowser": "^5.0.0",
"cordova-plugin-x-socialsharing": "^6.0.3",
"rxjs": "~6.6.0",
"tslib": "^2.0.0",
"zone.js": "~0.10.2"
},
"devDependencies": {
"#angular-devkit/build-angular": "~0.1101.4",
"#angular/cli": "~11.1.4",
"#angular/compiler": "~11.2.0",
"#angular/compiler-cli": "~11.2.0",
"#angular/language-service": "~11.2.0",
"#capacitor/cli": "2.4.7",
"#ionic/angular-toolkit": "^3.1.0",
"#types/jasmine": "~3.6.0",
"#types/jasminewd2": "~2.0.3",
"#types/node": "^12.11.1",
"codelyzer": "^6.0.0",
"jasmine-core": "~3.6.0",
"jasmine-spec-reporter": "~5.0.0",
"karma": "~5.2.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.0.3",
"karma-coverage-istanbul-reporter": "~3.0.2",
"karma-jasmine": "~4.0.0",
"karma-jasmine-html-reporter": "^1.5.0",
"protractor": "~7.0.0",
"ts-node": "~8.3.0",
"tslint": "~6.1.0",
"typescript": "~4.0.2"
},
"description": "An Ionic project"
}
I am trying to use this plugin cordova-plugin-x-socialsharing, but when importing it into the app.component.ts the application stops working.
This was the error displayed in the terminal:
Here is my app.component.ts:
import { NgModule } from '#angular/core';
import { BrowserModule } from '#angular/platform-browser';
import { RouteReuseStrategy } from '#angular/router';
import { IonicModule, IonicRouteStrategy } from '#ionic/angular';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { HttpClientModule } from '#angular/common/http'
import { SocialSharing } from '#ionic-native/social-sharing/ngx'; ****
#NgModule({
declarations: [AppComponent],
entryComponents: [],
imports: [
BrowserModule,
IonicModule.forRoot(),
AppRoutingModule,
HttpClientModule
],
providers: [
SocialSharing,****
{ provide: RouteReuseStrategy,
useClass: IonicRouteStrategy }],
bootstrap: [AppComponent],
})
export class AppModule {}
As soon as I import the native plugin and update the application it stops working.
Hello is what you declared in your app.module.ts and add commands
ionic cordova plugin add cordova-plugin-x-socialsharing
and
npm install #ionic-native/social-sharing
#NgModule({
declarations: [
AppComponent,
...
],
entryComponents: [
...
],
imports: [
...
],
providers: [
// it must be declared here
Social-sharing,
StatusBar,
SplashScreen,
ScreenOrientation,
InAppBrowser,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
],
bootstrap: [AppComponent]
})
export class AppModule {
}

UNMET PEER DEPENDENCY error for ionic-paypal

I was trying to install paypal & onesignal plugin from official website with the help of official documentations and I got this error:
+-- UNMET PEER DEPENDENCY #ionic-native/core#4.3.2
`-- #ionic-native/paypal#5.30.0
Here is my Package.json
{
"name": "ionic-hello-world",
"version": "0.0.0",
"author": "Ionic Framework",
"homepage": "http://ionicframework.com/",
"private": true,
"scripts": {
"clean": "ionic-app-scripts clean",
"build": "ionic-app-scripts build",
"lint": "ionic-app-scripts lint",
"ionic:build": "ionic-app-scripts build",
"ionic:serve": "ionic-app-scripts serve"
},
"dependencies": {
"#angular/common": "5.0.0",
"#angular/compiler": "5.0.0",
"#angular/compiler-cli": "5.0.0",
"#angular/core": "5.0.0",
"#angular/forms": "5.0.0",
"#angular/http": "5.0.0",
"#angular/platform-browser": "5.0.0",
"#angular/platform-browser-dynamic": "5.0.0",
"#ionic-native/core": "4.3.2",
"#ionic-native/onesignal": "^5.30.0",
"#ionic-native/paypal": "^5.30.0",
"#ionic-native/splash-screen": "4.3.2",
"#ionic-native/status-bar": "4.3.2",
"#ionic/storage": "2.1.3",
"ionic-angular": "3.9.2",
"ionicons": "3.0.0",
"rxjs": "5.5.2",
"sw-toolbox": "3.6.0",
"woocommerce-api": "^1.5.0",
"zone.js": "0.8.18"
},
"devDependencies": {
"#ionic/app-scripts": "^3.2.4",
"typescript": "2.4.2"
},
"cordovaPlugins": [
"ionic-plugin-keyboard",
"cordova-plugin-whitelist",
"cordova-plugin-statusbar",
"cordova-plugin-device",
"cordova-plugin-console",
"cordova-plugin-splashscreen"
],
"cordovaPlatforms": [],
"description": "ClickThrough: An Ionic project"
}
The PayPal service used by ionic-native/paypal has been deprecated for years and is end of life on December 7.
You should instead integrate the v2/checkout/orders API from a server, with or without the JS front end for the approval flow.
Approval requires a full mobile browser or SFSafariViewController/Chrome Custom Tabs. Approval cannot be given in a WKWebView or similar.

Ionic native calendar TypeError: Object(...) is not a function

I've just installed the ionic native calendar plugin for phone gap, based on the instructions here: https://ionicframework.com/docs/v3/native/calendar/
When I call anything like hasWritePermission() I get the following error:
index.js:685 Uncaught TypeError: Object(...) is not a function
at index.js:685
at Module../node_modules/#ionic-native/calendar/index.js (index.js:888)
at __webpack_require__ (bootstrap:83)
at Module../src/app/modals/event-detail-modal/event-detail-modal.component.ts (main.js:2401)
at __webpack_require__ (bootstrap:83)
at Module../src/app/app.module.ts (app.component.ts:13)
at __webpack_require__ (bootstrap:83)
at Module../src/main.ts (main.ts:1)
at __webpack_require__ (bootstrap:83)
at Object.0 (main.ts:12)
I'm using ionic 4 and angular 7, I'm wondering if this is down to unsupported dependencies? If it is, is there a more up to date plugin I can use, or am I doing something wrong here?
CODE: (addToCalendar method at the bottom)
import { Component, OnInit } from '#angular/core';
import {ModalController, NavParams} from "#ionic/angular";
import {ActivatedRoute, ActivatedRouteSnapshot} from "#angular/router";
import {Calendar} from "#ionic-native/calendar";
interface EventsInterface {
title: string;
startTime: Date;
endTime: Date;
ID: number;
categoriesString: string;
description: string;
recurring: boolean;
recurFrequency: string;
thumbnail: string;
}
#Component({
selector: 'app-event-detail-modal',
templateUrl: './event-detail-modal.component.html',
styleUrls: ['./event-detail-modal.component.scss'],
})
export class EventDetailModalComponent implements OnInit {
/**
*
*/
public event: EventsInterface = null;
/**
*
* #param modalController
* #param navParams
*/
constructor(private calendar: Calendar,private modalController: ModalController, private navParams: NavParams) { }
/**
*
* #param route
*/
ngOnInit() {
// get the event
this.event = <EventsInterface>this.navParams.get('event');
console.log(this.event);
}
/**
*
*/
dismiss(){
return this.modalController.dismiss({
'dismissed':true
});
}
addToCalendar(event: EventsInterface){
this.calendar.hasWritePermission().then((resp: any)=>{
console.log(resp)
}).catch((resp: any) =>{
console.log(resp);
});
}
}
As you can see, I've done very little so far execpt install the plugins and setup a simple promise catch...
EDIT
p
It appears to be related to the wrong versions of some libraries, when installing with nom it warns:
npm WARN #ionic-native/calendar#4.20.0 requires a peer of #ionic-native/core#^4.11.0 but none is installed. You must install peer dependencies yourself.
npm WARN #ionic-native/calendar#4.20.0 requires a peer of rxjs#^5.5.11 but none is installed. You must install peer dependencies yourself.
The problem with this is the rest of the app is using ionic native 5.0.0 and rxjs 6.5.1 and for some reason the calendar component won't work with these newer versions?
Here is the package file:
{
"name": "V3",
"version": "0.0.1",
"author": "Ionic Framework",
"homepage": "https://ionicframework.com/",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"#angular/common": "^7.2.2",
"#angular/core": "^7.2.2",
"#angular/forms": "^7.2.2",
"#angular/http": "^7.2.15",
"#angular/platform-browser": "^7.2.2",
"#angular/platform-browser-dynamic": "^7.2.2",
"#angular/router": "^7.2.2",
"#ionic-native/calendar": "^4.20.0",
"#ionic-native/core": "^5.0.0",
"#ionic-native/in-app-browser": "^5.12.0",
"#ionic-native/native-page-transitions": "^5.8.0",
"#ionic-native/splash-screen": "^5.0.0",
"#ionic-native/status-bar": "^5.0.0",
"#ionic/angular": "^4.1.0",
"#ionic/storage": "^2.2.0",
"#types/jquery": "^3.3.31",
"chart.js": "^2.8.0",
"cordova-ios": "4.5.5",
"cordova-plugin-calendar": "^5.1.4",
"cordova-plugin-device": "^2.0.2",
"cordova-plugin-inappbrowser": "^3.1.0",
"cordova-plugin-ionic-keyboard": "^2.1.3",
"cordova-plugin-ionic-webview": "^4.1.1",
"cordova-plugin-splashscreen": "^5.0.2",
"cordova-plugin-statusbar": "^2.4.2",
"cordova-plugin-whitelist": "^1.3.3",
"cordova-sqlite-storage": "^3.2.0",
"core-js": "^2.5.4",
"intl": "^1.2.5",
"ion4-calendar": "^3.0.4-beta.17",
"ionic2-calendar": "^0.5.2",
"jquery": "^3.4.1",
"moment": "^2.24.0",
"ng2-file-upload": "^1.3.0",
"rxjs": "~6.5.1",
"tslib": "^1.9.0",
"zone.js": "~0.8.29"
},
"devDependencies": {
"#angular-devkit/architect": "~0.13.8",
"#angular-devkit/build-angular": "~0.13.8",
"#angular-devkit/core": "~7.3.8",
"#angular-devkit/schematics": "~7.3.8",
"#angular/cli": "~7.3.8",
"#angular/compiler": "~7.2.2",
"#angular/compiler-cli": "~7.2.2",
"#angular/language-service": "~7.2.2",
"#ionic/angular-toolkit": "~1.5.1",
"#types/node": "~12.0.0",
"#types/jasmine": "~2.8.8",
"#types/jasminewd2": "~2.0.3",
"codelyzer": "~4.5.0",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~4.1.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~1.1.2",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.4.0",
"ts-node": "~8.3.0",
"tslint": "~5.17.0",
"typescript": "~3.1.6"
},
"description": "An Ionic project",
"cordova": {
"plugins": {
"cordova-plugin-whitelist": {},
"cordova-plugin-statusbar": {},
"cordova-plugin-device": {},
"cordova-plugin-splashscreen": {},
"cordova-plugin-ionic-webview": {},
"cordova-plugin-ionic-keyboard": {},
"cordova-sqlite-storage": {},
"cordova-plugin-inappbrowser": {},
"cordova-plugin-calendar": {
"CALENDAR_USAGE_DESCRIPTION": " ",
"CONTACTS_USAGE_DESCRIPTION": " "
}
},
"platforms": [
"ios"
]
}
}

Cannot find namespace 'moment'

I am using ionic 2.
I create new project
ionic start Ismart --v2
The project was successfully created.
I tried to run the project using ionic serve
I am getting this err
Cannot find namespace 'moment'
Here is my Package.Json
{
"name": "ionic-hello-world",
"version": "0.0.0",
"author": "Ionic Framework",
"homepage": "http://ionicframework.com/",
"private": true,
"scripts": {
"clean": "ionic-app-scripts clean",
"build": "ionic-app-scripts build",
"ionic:build": "ionic-app-scripts build",
"ionic:serve": "ionic-app-scripts serve"
},
"dependencies": {
"#angular/common": "4.0.2",
"#angular/compiler": "4.0.2",
"#angular/compiler-cli": "4.0.2",
"#angular/core": "4.0.2",
"#angular/forms": "4.0.2",
"#angular/http": "4.0.2",
"#angular/platform-browser": "4.0.2",
"#angular/platform-browser-dynamic": "4.0.2",
"#ionic-native/core": "3.4.2",
"#ionic-native/splash-screen": "3.4.2",
"#ionic-native/status-bar": "3.4.2",
"#ionic/storage": "2.0.1",
"ionic-angular": "3.1.0",
"ionicons": "3.0.0",
"rxjs": "5.1.1",
"sw-toolbox": "3.4.0",
"zone.js": "^0.8.5"
},
"devDependencies": {
"#ionic/app-scripts": "1.3.6",
"typescript": "~2.2.1"
},
"cordovaPlugins": [
"cordova-plugin-whitelist",
"cordova-plugin-console",
"cordova-plugin-statusbar",
"cordova-plugin-device",
"cordova-plugin-splashscreen",
"ionic-plugin-keyboard"
],
"cordovaPlatforms": [],
"description": "ISmartpremises: An Ionic project"
}
How can i fix this issue...
Kindly advice me,
Thanks
I cannot see any issue in your package.json file.I think you have forgotten to change the directory.
You can try as shown below.
d:\ionic2 > ionic start Ismart blank --v2
d:\ionic2\Ismart> ionic serve