I'm trying to use camanjs library in my ionic v3 project. I installed it using npm install caman --save (also installed cairo, libjpg and libpng). Now in my project folder I can see a folder named caman in node_modules folder, so in my .ts I write
import { Component } from '#angular/core';
import { NavController } from 'ionic-angular';
import { Caman } from 'caman';
declare var Caman: any;
#Component({
selector: 'page-filtri',
templateUrl: 'filtri.html'
})
export class FiltriPage {
constructor(public navCtrl: NavController) {
}
addFilter(){
Caman("#image", function(){
this.sinCity();
this.render();
})
}
}
and the html file
<ion-header>
<ion-navbar>
<ion-title>
Ionic Blank
</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<button ion-button (click)="addFilter()">Filtro</button>
<img id='image' src="https://firebasestorage....">
</ion-content>
but if I serve I've
ERROR ReferenceError: Caman is not defined
And that's how my node_modules folder looks like
[node_modules folder]
Can you help me?
Why don't you try changing your import to the following:
import * as Caman from 'caman';
You cannot declare both at the same time like this.
import { Caman } from 'caman';
declare var Caman: any;
you only need to use
import { Caman } from 'caman';
But you get the error "Module parse failed: ...." There is nothing wrong with the import it is because of the CamanJs Uses node-canvas. And canvas loads binary files. like "canvas.node". You need to install node-loader https://github.com/webpack-contrib/node-loader to resolve that error.
Related
I need to open payment method url inside ionic app, but i didn't found any solution of that. I have tried Iframe but it doesn't work for payment method urls, because of security reasons i guess. I have also treid InAppBrowser that doesn't work.
What I have tried open the url in browser but i need it to open within app.
Any solution?
You can use InAppBrowser-plugin to open an external url.
Install:
ionic plugin add cordova-plugin-inappbrowser --save
npm install --save #ionic-native/in-app-browser
See here:
import { Component , OnInit } from '#angular/core';
import { NavController } from 'ionic-angular';
import { InAppBrowser } from '#ionic-native/in-app-browser';
#Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage implements OnInit{
constructor(public navCtrl: NavController,private iab: InAppBrowser) {
}
ngOnInit(){
const browser = this.iab.create('https://www.stackoverflow.com','_self',{location:'no'});
}
}
I want to use ion-slides method getActiveIndex() but when I import ion-slides as a provider, I have this error :
NullInjectorError: No provider for ChangeDetectorRef!
I don't know why I have to add this to providers. Even if I add this, I have the other provider: ElementRef...
If you have a look at my code, could you tell me if I'm doing something wrong?
thanks!
liste.page.ts :
import {IonSlides} from '#ionic/angular';
#Component({
selector: 'app-liste',
templateUrl: './liste.page.html',
styleUrls: ['./liste.page.scss'],
})
export class ListePage {
constructor(private ionSlides: IonSlides) { }
slideChanged() {
console.log(this.ionSlides.getActiveIndex());
}
}
liste.page.html:
<ion-slides [options]="sliderConfig" (ionSlideTransitionEnd)="slideChanged()">
<ion-slide *ngFor="let item of items; let i = index">
{{item.name}}
</ion-slide>
</ion-slides
Ionic Info:
ionic (Ionic CLI) : 4.9.0
Ionic Framework : #ionic/angular 4.1.2
#angular-devkit/build-angular : 0.13.6
#angular-devkit/schematics : 7.2.4
#angular/cli : 7.3.6
#ionic/angular-toolkit : 1.4.1
In your liste.page.html use:
<ion-slides pager="true" #slides>
Then you can reference it in your liste.page.ts file with:
import {IonSlides} from '#ionic/angular';
import {ViewChild} from '#angular/core'; // <----
[...]
export class ListePage {
#ViewChild('slides', { read: IonSlides }) slides: IonSlides; // <----
Then you have access to slides and can call getActiveIndex();
slideChanged() {
console.log(this.slides.getActiveIndex());
}
Below worked for me
import {IonSlides} from '#ionic/angular';
import {ViewChild} from '#angular/core'; // <----
[...]
export class ListePage {
#ViewChild('sliderRef', { static: true }) slides: IonSlides;
slideChanged(){
this.slides.getActiveIndex().then((val) =>{
console.log(val);
});
<ion-slides #sliderRef pager="true" [options]="slideOpts" (ionSlideDidChange)="slideChanged()" >
I am trying to use ionic 4 and cordova-plugin-file to get files from phone but it trows an error;
When i do console.log(cordova.file) like in the doc it shows cordova does not have property 'file'.
When i do
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, fail); it show 'requestFileSystem' not a property of window.
even if i do window.cordova it trow thesame error.
and unlike ionic 3 here if i add File to providers it trows an error as well
Please what is it i'm doing wrong?
Here is my ** home.page.ts**
import {Component} from '#angular/core';
import {Platform} from '#ionic/angular';
import {File} from '#ionic-native/file';
#Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})
export class HomePage {
constructor(public platform: Platform) {
platform.ready().then(() => {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {
console.log(fileSystem)
}, function(error) {
console.log(error);
});
});
}
}
For Ionic 4 you should add 'ngx' at the end of the import.
Like this,
import {File} from '#ionic-native/file/ngx';
Make sure to add it to the providers list of your module file, and also inject it to the constructor of the class where ever you are using the plugin.
Reference https://ionicframework.com/docs/native
I'm using the ion-text-avatar module. I've imported it in the app.module.ts page but I still get the error as
ERROR Error: Uncaught (in promise): Error: Type IonTextAvatar is part
of the declarations of 2 modules: AppModule and
ConversationPageModule! Please consider moving IonTextAvatar to a
higher module that imports AppModule and ConversationPageModule. You
can also create a new NgModule that exports and includes IonTextAvatar
then import that NgModule in AppModule and ConversationPageModule.
Error: Type IonTextAvatar is part of the declarations of 2 modules:
AppModule and ConversationPageModule! Please consider moving
IonTextAvatar to a higher module that imports AppModule and
ConversationPageModule. You can also create a new NgModule that
exports and includes IonTextAvatar then import that NgModule in
AppModule and ConversationPageModule
This is my conversationPage code.
<ion-content>
<ion-list>
<ion-item>
<ion-avatar item-start ion-checkbox checked="true">
<ion-text-avatar shape="round" class="avatar font">
{{ }}
</ion-text-avatar>
<ion-icon name="checkmark-circle"></ion-icon>
</ion-avatar>
<h6>{{ }}</h6>
</ion-item>
</ion-list>
</ion-content>
I have also imported & declared the module in the declarations of conversation.module.ts. How can I solve this issue?
The error says that IonTextAvatar is part of 2 modules, which is bad. If you use it only in your Conversation page, you should remove it from your AppModule, and import it only in ConversationPageModule:
import { IonTextAvatar } from 'ionic-text-avatar';
#NgModule({
declarations: [
IonTextAvatar
]
})
export class ConversationPageModule {}
I want to make webview to show my webpage with crosswalk plugin. When I put my url, and click the button. I got error
"Application Error"
"net:ERR_INSECURE_RESPONSE
(https://example.dummy.com:8444)"
my home page is using https
this is my code :
home.html
<ion-slide>
<h2>Please, Enjoy to call with our customer service</h2>
<button ion-button block full (click)="goToPage('https://oscar2.kebhana.co.id:8444/gibPT/intn/info/call#359854')">Start Video Call</button>
</ion-slide>
home.ts
import { Component } from '#angular/core';
import { NavController } from 'ionic-angular';
#Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
constructor(public navCtrl: NavController) {
}
goToPage(url : string) {
window.open(url, '_self');
}
}
Please help me to fix. Thank you
#anggaerlangga you can use InAppBrowser to open an external link. because IONIC is not a web application you have to use any browser for open external URL. I will show you how can you use the InAppBrowser.
first of all you have to install InAppBrowser NPM from the ionic native.
import { InAppBrowser} from '#ionic-native/in-app-browser';
let baseurl = 'your url';
let target = "_blank";
this.iab.create(baseurl,target);
Thank you. this will definitely help you.