Quantcast
Channel: Ionic Forum - Latest posts
Viewing all 228527 articles
Browse latest View live

Nested component not updating view from parent parameter

$
0
0

@rapropos sure! I still stripped out a decent amount from each file, this is a very rough/work in progress project so I have a lot of unneeded/extra code that I don’t want to confuse, but I’ll include both below with a description.

I realize I made the Player component as a page rather than a component, but I don’t think that should be causing problems. To give a brief description, DemoPage (or any page that I want the player to show on) imports and passes the PlayerPage into the constructor, and when that page hits ionViewDidLoad, it calls the player to set up the HammerJS associated with the player. When a user hits the playSong function, some logic is done to move the player into the view and then passes the song name from DemoPage into setSong() in Player.ts. I am seeing this.accessToken set correctly in the controller, but it doesn’t reflect the update in the view. Please let me know if anything looks incorrect to you. Thank you!

Demo.ts - Parent Page

import { Component, NgZone } from '@angular/core';
import { Platform, ModalController, NavController, NavParams } from 'ionic-angular';
import { HTTP } from '@ionic-native/http';
import { Storage } from '@ionic/storage';
import sampleTracks from "../../assets/sampleMusic.js";

import { ErrorModalPage } from '../errorModal/errorModal';
import { PlayerPage } from '../player/player'

@Component({
  selector: 'page-demo',
  templateUrl: 'demo.html'
})

export class DemoPage {

  result = {}

  pictureList: any[];

  previousPlayedTrack = { active: false };

  recommendedTracksJson = [{}]
  height: any

  // poor choice here, but to keep it simple
  // setting up a few vars to keep track of things.
  // at issue is these values need to be encapsulated
  // in some scope other than global.
  lastPosX = 0;
  lastPosY = 0;
  isDragging = false;
  activeSong: string
  playingTrack = false;
  timerId: any

  constructor(public modalController: ModalController,
              public navCtrl: NavController,
              public platform: Platform,
              private http: HTTP,
              public navParams: NavParams,
              public ngZone: NgZone,
              private player: PlayerPage,
              public storage: Storage) {

              this.recommendedTracksJson = sampleTracks

              this.platform.ready().then(() => {

                this.height = this.platform.height()

              })

  }

  ionViewDidLoad() {
    this.player.setupPlayer()
  }

  playSong(event, item) {

    var myBlock = document.getElementById('myElement');

    myBlock.classList.add('animate');

    if(!item.active || item.active == false) {
      this.previousPlayedTrack.active = false;
      item.active = true;
      this.previousPlayedTrack = item
      this.player.activeSong = item.name
      this.player.setSong(item.name)
      myBlock.style.top = this.height * .9 + "px"
    } else {
      this.player.setSong("")
      item.active = false
      myBlock.style.top = this.height + "px"
    }

  }

}

Player.ts - Component

import { Component, NgZone } from '@angular/core';
import { IonicPage, Platform } from 'ionic-angular';
import Hammer from 'hammerjs';
/**
 * Generated class for the PlayerPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-player',
  templateUrl: 'player.html',
})

export class PlayerPage {

  height: any
  lastPosX = 0;
  lastPosY = 0;
  isDragging = false;
  activeSong: string = "Placeholder"
  playingTrack = false;
  timerId: any

  constructor(public ngZone: NgZone, public platform: Platform) {

    this.platform.ready().then(() => {

      this.height = this.platform.height()

    })

  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad PlayerPage');
  }

  setupPlayer() {

    var myBlock = document.getElementById('myElement');

    if (myBlock != null) {

      var screenBottom = this.height
      var screenMiddle = this.height * 0.9
      var screenTop = this.height * 0.2

      // create a simple instance on our object
      var mc = new Hammer(myBlock);

      // add a "PAN" recognizer to it (all directions)
      mc.add( new Hammer.Pan({ direction: Hammer.DIRECTION_ALL, threshold: 0 }) );

      // tie in the handler that will be called
      mc.on("pan", this.handleDrag.bind(this), this.handleDrag);
      // mc.on("pandown", handleDragDown);
      var Tap = new Hammer.Tap({
        taps: 1
      });

      mc.add(Tap)

      mc.on('tap', this.handleTap.bind(this), this.handleTap)

    } else {
      console.log("Null block 2")
    }

  }

  setSong(song) {
    this.ngZone.run(() => {
        this.activeSong = song;
    });

    console.log("Active song: " + this.activeSong)
  }

  handleTap(ev) {
    var elem = ev.target;
    document.getElementById('myElement').classList.add('animate');
    elem.style.top = this.height * 0.2 + "px"
  }

  handleDrag(ev) {

    var screenBottom = this.height
    var screenMiddle = this.height * 0.9
    var screenTop = this.height * 0.2

    // for convience, let's get a reference to our object
    var elem = ev.target;
    document.getElementById('myElement').classList.remove('animate');
    // DRAG STARTED
    // here, let's snag the current position
    // and keep track of the fact that we're dragging
    if ( ! this.isDragging ) {
      this.isDragging = true;
      this.lastPosX = elem.offsetLeft;
      this.lastPosY = elem.offsetTop;
    }

    // we simply need to determine where the x,y of this
    // object is relative to where it's "last" known position is
    // NOTE:
    //    deltaX and deltaY are cumulative
    // Thus we need to always calculate 'real x and y' relative
    // to the "lastPosX/Y"

    var posY = ev.deltaY + this.lastPosY;
    elem.style.top = posY + "px";

    // DRAG ENDED
    // this is where we simply forget we are dragging
    if (ev.isFinal) {

      var verticalDirection = this.lastPosY - posY

      var positionAbove
      var positionBelow
      var closestPosition

      if (posY <= screenMiddle) {
        positionAbove = screenTop
        positionBelow = screenMiddle
      } else {
        positionAbove = screenMiddle
        positionBelow = screenBottom
      }

      if ((posY - positionAbove) < (positionBelow - posY)) {
          closestPosition = positionAbove
      } else {
          closestPosition = positionBelow
      }

      document.getElementById('myElement').classList.add('animate');

      if (verticalDirection < 0) {
          elem.style.top = positionBelow + "px"
      } else if (verticalDirection > 0 ){
          elem.style.top = positionAbove + "px"
      } else {
          elem.style.top = closestPosition + "px"
      }

      this.isDragging = false;

    }
  }

}

Issue on Ionic 4 with Razorpay payment gateway

$
0
0

I am using razorpay payment gateway for my ionic shopping app. using latest Razorpay cordova plugin. The problem is there two callback functions cancel and success. It works fine, But if the payment process takes time like 2minutes i am not getting any response/not executing any of this callback functions.

Help me to resolve this issue ?

I want to build video editor application

$
0
0

Hello,
I can help you with your requirement
Are you still looking for help?

Regards,
Nicole

Nested component not updating view from parent parameter

$
0
0

OK, this is the problem. You can’t inject pages (or components) like this. Emulate the stuff documented here using an @Input binding (or use a mutually injected service).

New ios version build- Layout issue with soft-keyboard & intermittent Speech Recognition issues

$
0
0

Issues:

  1. Layout of the screen doesn’t auto-adjust as the soft keyboard pops up.
  2. Speech recognition mic cuts-off after a moment or so. Sometime after multiple tries works as expected and continues processing speech to text as long as the user speaks.

Background:
Using the following

“cordova-ios”: “^5.0.0”
“ionic-angular”: “3.9.2”
@ionic/app-scripts”: “^3.1.8”
@ionic-native/keyboard”: “^4.20.0”

Was working with build from a mac with the following :
macOS High Sierra Version 10.13.6
Xcode 10.1 10B61

Not working with build from a mac with the following:
macOS Catalina Version 10.15.3
Xcode 11.3.1 11C504

What are the things that i should be looking into when doing something like this.
TIA

Ionic 5 & Phaser 3

$
0
0

Someone has any idea?

Thank you very much! :slight_smile:

Socket Io not working

$
0
0

Hello, I’m implementing Socket io in my ionic project. But having an issue, while creating an apk and running that on Android version 5 and 6 i’m getting an error in console undefined identifier. While running same apk on Android 7+ its working fine.
While debugging the error i found the error in app.module.ts file:

import { SocketIoModule, SocketIoConfig } from 'ngx-socket-io';
const config: SocketIoConfig = { url: 'http://localhost:81', options: {} };

imports: [BrowserModule, HttpClientModule, IonicModule.forRoot(), AppRoutingModule, SocketIoModule.forRoot(config) ],

Having error in these. When i comment out these its working fine in all version of Android.
In web view its working fine while commenting and uncommenting these lines.

SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

$
0
0

IONIC -5
access-provider.ts

export class AccessProviders{
    server:string='http://localhost/api/';
    constructor(private http:HttpClient
        ) { }

        postData(body,file){
            let headers=new HttpHeaders({
            'Content-Type':'application/json; charset=UTF-8'
            });
            let options= { 
                headers : headers
            }
            return this.http.post(this.server + file , JSON.stringify(body),options)
            .timeout(590000)
            .map(res=>res);
  
        }
       
   }

register.ts

async tryRegister(){
        if(this.your_name==""){
        this.presentToast('your name is required');
        }else if(this.email_address==""){
          this.presentToast('Email is required');
        }else if(this.password==""){
        this.presentToast('password is required');
        }else if(this.confirm_pass!=this.password){
        this.presentToast('Password not match');
        }else{
        this.disabledButton=true;
        const loader = await this.load.create({
        message:'Please Wait.....',
    });
    loader.present();
  return new Promise(resolve=>{
    let body = {
    aksi: 'process_register',
    your_name: this.your_name,
    email_address: this.email_address,
    password: this.password,
    confirm_pass: this.confirm_pass
    }
   

this.accsPrvds.postData(body,'process_api.php').subscribe((res:any)=>{
console.log("hello");
if(res.success == 'true'){
loader.dismiss();
this.disabledButton=false;
this.presentToast(res.msg);
this.router.navigate(['/login']);
}else {
  loader.dismiss();
  this.disabledButton=false;
  this.presentToast(res.msg); 

}

},(err)=>{
  loader.dismiss();
  this.disabledButton=false;
  this.presentAlert('Timeout');
});

    });
  }



  }

process_api.php

<?php

header('Access-Control-Allow-Orgin: *');

header("Access-Control-Allow-Credentials: true");
header("Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS");
header("Access-Control-Allow-Headers: Origin,Content-Type,Authorization,Accept,X-Requested-With,x-xsrf-token");
header("Content-Type: application/json;charset=utf-8");
include "config.php";
$postjson=json_decode(file_get_contents('php://input'),true);

if($postjson['aksi']=="process_register"){
  
          $checkmail=mysqli_fetch_array(mysqli_query($mysqli,"SELECT email_address FROM register WHERE email_address='$postjson[email_address]'"));

          if($checkmail['email_address']==$postjson['email_address']){
            $result=json_encode(array('success'=>false,'msg'=>'Email Already Registered'));
          }else{

                $password=md5($postjson['password']);

                $insert = mysqli_query($mysqli,"INSERT INTO register SET 
                your_name ='$postjson[your_name]',
                email_address ='$postjson[email_address]', 
                password ='$password', 
                confirm_pass ='$postjson[confirm_pass]'
                
                ");
                if($insert){
                    $result=json_encode(array('success'=>true,'msg'=>'Register Successfully'));
                }else{
                    $result=json_encode(array('success'=>false,'msg'=>'Register error'));
                }

          }
          echo $result;
}
?>

config.php

<?php
define('db_name','ionic_db');
define('db_user','root');
define('db_pass','');
define('db_host','localhost');
$mysqli = new mysqli(db_host,db_user,db_pass,db_name);
if ($mysqli->connect_error) {
    die("Connection failed: " . $mysqli->connect_error);
}
echo "Connected successfully";

?>

The user register successful but it shows time out message for this.accsPrvds.postData(body,‘process_api.php’).subscribe((res:any)=>{ } function please Help


SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

$
0
0

You are sending array in Api and on php it isn’t accepting array you can try like:

let body = 'aksi=process_register' + 'your_name=' + this.your_name + 'email_address=' + this.email_address + 'password=' + this.password + 'confirm_pass=' +this.confirm_pass ;

Installed ionic but giving error ionic command not found

$
0
0

Hi Team,

I already installed the ionic and cordova but its giving error that ionic command not found, i already remove the ionic and cordova and install again but still facing same issue.

i already tried to remove the node but still facing same issue, could any one please help me for resolving the issue.

MACPRO21:bin jitendra.naithani$ npm install -g ionic

npm WARN deprecated ionic@5.4.16: The Ionic CLI now uses :sparkles: @ionic/cli :sparkles: for its package name! :point_right: https://twitter.com/ionicframework/status/1223268498362851330

npm WARN deprecated superagent@4.1.0: Please note that v5.0.1+ of superagent removes User-Agent header by default, therefore you may need to add it yourself (e.g. GitHub blocks requests without a User-Agent header). This notice will go away with v5.0.2+ once it is released.

/usr/local/bin/bin/ionic -> /usr/local/bin/lib/node_modules/ionic/bin/ionic

  • ionic@5.4.16

updated 1 package in 11.832s

MACPRO21:bin jitendra.naithani$ ionic info

-bash: ionic: command not found

SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

$
0
0

Ok thank you for your reply ,i checked but it shows similar error and user details not register to the database,extra one warning( Illegal string offset ‘aksi’ in /Applications/XAMPP/xamppfiles/htdocs/api/process_api.php on line)

Multiple audio files with cordova-plugin-media on ios

$
0
0

I have the following code in my controller ( this project is in ionic 1, and uses the cordova-plugin-media 5.0.3 plugin):


.controller('AudioCtrl', function($scope) {
  console.log('in AudioCtrl');
  let AudioFiles =[
    {
      url:"sample.aac"
    },
    {
      url:"8b2d52b76e71729c8073b8340f7c0607.m4a"
    },
    {
      url:"test1.mp4"
    }
  ];
  $scope.MediaFiles = [];

  $scope.$on('$ionicView.beforeEnter',function(){

    angular.forEach(AudioFiles,function(val,key){
      console.log('adding',val);
      let tempMediaObject = new Media(val['url'],function(){
        //mediaSuccess
      },function(){
        //mediaError
      },function(){
        //mediaStatus
      });
      $scope.MediaFiles.push(tempMediaObject);
    });

    console.log($scope.MediaFiles);

  });

  $scope.play = function(index){
    console.log('play this file', $scope.MediaFiles[index]);
    $scope.MediaFiles[index].play();
  };

  $scope.pause = function(index){
    $scope.MediaFiles[index].pause();
    $scope.MediaFiles[index].release();
  };

  $scope.stop  = function(index){
    $scope.MediaFiles[index].stop();
    $scope.MediaFiles[index].release();
  };

})

and the following code in my page:

    <div class="card">
      <div style="white-space: normal;display: block;">File URL: {{audio.src}}</div>
      <button class="button" ng-click="play($index)">Play</button>
      <button class="button" ng-click="pause($index)">Pause</button>
      <button class="button" ng-click="stop($index)">Stop</button>
    </div>

  </ion-item>
</ion-list>

The problem is that when I try playback, it always plays the audio file form the first Media object created(sample.aac). As you can see I have consoled logged the file that should be playing when I hit play and that is the correct file as selected, but what actually plays is always the first file. I have also tried this without the $scope.MediaFiles[index].release() call. This works fine on android but not on ios. I am testing on an iPhone X with ios 13.2.3. Anyone had this issue or know any solution ?

Sign in with Apple ID => Ionic Support?

$
0
0
import { Component, OnInit } from '@angular/core';
import { Validators, FormBuilder, FormGroup, FormControl } from '@angular/forms';
import { AuthNativeService } from 'src/app/services/auth.native.service';
import { Router } from '@angular/router';
import { AngularFirestore } from '@angular/fire/firestore';
import { NavController, ToastController, Platform } from '@ionic/angular';
import { AngularFireAuth } from '@angular/fire/auth';
import { Facebook } from '@ionic-native/facebook/ngx';
import { GooglePlus } from '@ionic-native/google-plus/ngx';
import * as firebase from 'firebase/app';
declare var SignInWithApple: any;
////////

async appleLogin() {
const appleUser = await SignInWithApple.request({
    requestedScopes: [ SignInWithApple.Scope.Email, SignInWithApple.Scope.FullName ],
  })
  var appleProvider = new firebase.auth.OAuthProvider('apple.com')
  await this.afAuth.auth.signInWithCredential(appleProvider.credential(appleUser.identityToken)).then(res => console.log(res, 'risposta auth'))
  this.router.navigate(["/tabs/home"]);
  }
  catch(error) { console.log("ERROR: " +error) };
}

That’s what worked for me. Hope it helps!

Ionic v2 . Video is not playing on android 9 and higher versions Ask

$
0
0

I am working on an ionic v2 app. the issue only raised in android v9 and v10 . Below android v9 and iPhone build, video is playing fine. Blank screen is appearing without any active option.

Cordova CLI: 7.1.0

Ionic CLI Version: 2.2.1

Ionic App Lib Version: 2.2.0

ios-deploy version: 1.10.0

ios-sim version: 8.0.2

OS: macOS

Node Version: v10.18.0

Xcode version: Xcode 10.3 Build version 10G8

Ionic 5 & Phaser 3

$
0
0
  1. remove <script src="assets/phaser.js"></script> in index.html
  2. in root folder: angular.json, search "scripts": [], add your js file.
    eg: "scripts": ["src/phaser.min.js"]
  3. restart ng serve, ‘phaser’ should work.

Modify shadow-root styles

InAppbrowser not working in Android Emulator

$
0
0

Can anyone suggest me KO player or Nox player 6 emulator which one is more compatible in windows pcs??

[Ionic V4]How to remove last-child bottom border of ion-item in Ionic4

$
0
0

this is my solution , it works for me , i use ionic 4

<ion-list class="no-last-border">...</ion-list>

and in css i use below :

ion-list.no-last-border {
  :last-child {
    --border-style: none !important;
  }
}```

Ion-searchbar: pass filtered list results to another page

$
0
0

Thanks for your answer!

Could you please show me a short snippet, maybe how could be the observable in that context?

Whatsapp - share multiple files at once Ionic4

$
0
0

I am trying to find a solution for share multiple files to whatsapp, with only one click.

Example:
-> Have 3 files of the product.
-> User click only one time
-> The app share the 3 documents (PDF, EXCEL…)

Is it possible?

Viewing all 228527 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>