Quantcast
Channel: Ionic Forum - Latest topics
Viewing all 71531 articles
Browse latest View live

Angular 9 HTTP Post request Error. You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable

$
0
0

Hi,
I have been setting up a app.service file for various API calls to a backend system. I recently upgraded the platform from Ionic 3 to Ionic 5 and I did the appropriate updates to the HTTP request library. But whenever I try to make a call to the API I always receive the following error:

vendor.js:42843 ERROR TypeError: You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable.
    at subscribeTo (vendor.js:121254)
    at subscribeToResult (vendor.js:121414)
    at CatchSubscriber.push../node_modules/rxjs/_esm5/internal/operators/catchError.js.CatchSubscriber.error (vendor.js:113654)
    at MapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._error (vendor.js:110606)
    at MapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.error (vendor.js:110586)
    at MapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._error (vendor.js:110606)
    at MapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.error (vendor.js:110586)
    at FilterSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._error (vendor.js:110606)
    at FilterSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.error (vendor.js:110586)
    at MergeMapSubscriber.push../node_modules/rxjs/_esm5/internal/OuterSubscriber.js.OuterSubscriber.notifyError (vendor.js:110097)

This is the API function that is called whenever a user tries to log in:

import {throwError as observableThrowError, Observable} from 'rxjs';

import {catchError, map} from 'rxjs/operators';
import {Component, ViewChild} from '@angular/core';
import {Injectable} from '@angular/core';
import {HttpClient, HttpHeaders} from '@angular/common/http';
import {env} from '../env/env';
import {ToastController, IonApp, NavController} from '@ionic/angular';

import {NavigationExtras} from '@angular/router';

@Injectable()
export class ApiService {
    httpOptions = {
        headers: new HttpHeaders({
            'Content-Type': 'application/json',
            'No-Auth': 'True',
        }),
    };
  constructor(
      private http: HttpClient,
      public toastCtrl: ToastController,
      public appCtrl: NavController,
      // public device: Device
  ) {
  }
addUser(user) {

    const headers = new HttpHeaders();
    headers.append('Accept', 'application/json');
    headers.append('Content-Type', 'application/json');
    const requestOptions = {headers};

    let userDob = user.dob.split('-');
    userDob = userDob.join('/');

    const optInDate = new Date();
    const month = optInDate.getMonth() + 1;
    const day = optInDate.getDate();
    const year = optInDate.getFullYear();
    const oDate = month + '/' + day + '/' + year;


    return new Promise<any>((resolve, reject) => {
      const payload = {
        firstName: user.firstname,
        middleName: '',
        lastName: user.lastname,
        doorNo: user.address,
        streetAddress: '',
        city: user.city,
        state: user.state,
        zip: user.zipcode,
        country: 'US',
        gender: user.gender,
        dateOfBirth: userDob,
        emailId: user.email,
        patientConsent: 'Y',
        phoneNo: user.mobile,
        optIn: oDate,
        optOut: oDate,
        userType: 'AppUser'
      };

      this.http.post(`${env.baseApiUrl}/addUser/`, payload, this.httpOptions).pipe(
            map((res: Response) => res),
            catchError(error => {
                console.log(error);
                reject(error);
                // changes made by Jas 2020_03_31 changed toast
                this.showLongToast('Inside Send Verification Code Method');
                return this.handleError(error);
            }), ).subscribe(data => resolve(data));
          });
  }

This is where I am calling the actual function to log the user in, contained within the login.page.ts:

 signIn() {

    if ( (this.user.username) && (this.user.password) ) {

      this.loadingCtrl.create({
        message: 'Please wait...'
      }).then((res) => {
        res.present();

        this.ApiService.login(this.user)
            .then(r => {
              localStorage.setItem('userToken', r.token);
              localStorage.setItem('userId', r.userId);

              // Check if user has reminders.
              this.ApiService.getReminders()
                  .then(r => {
                    res.dismiss();
                    this.navCtrl.navigateRoot('/dashboard');
                    this.ApiService.showToast('Logged In');
                  })
                  .catch(e => {
                    this.navCtrl.navigateRoot('/medicines');
                    res.dismiss();
                    this.ApiService.showToast('Logged In');
                  });

              this.menuCtrl.enable(true);
              this.menuCtrl.get().then((menu: HTMLIonMenuElement) => {
                menu.swipeGesture = true;
              });

              if (localStorage.getItem('userNotifications') === null) {
                localStorage.setItem('userNotifications', JSON.stringify([]));
              }

            })
            .catch(e => {
              console.log (e);
              if (e.status == '404') {
                this.ApiService.showToast('User does not exist');
              }
              if (e.status == '400') {
                this.ApiService.showToast('Invalid credentials');
                this.showForgotPassword = true;
              }
              res.dismiss();
            });
      });
    } else {
      this.ApiService.showToast('Please enter username and password');
    }

  }

1 post - 1 participant

Read full topic


Ionic4 / Firebase Real time db / javascript / snapshot / how to get data for real

$
0
0

Hello,

I start using Firebase real time db and I’d like to know how to extract data quick and easy.

Here is my code:

this.MyFormula = ref.once(“value”).then(function(snapshot) {
snapshot.forEach(function(childSnapshot) {
var childData = childSnapshot.val();
childData.key = childSnapshot.key;
returnArr.push(childData);
console.log(“This display works well:”,childData);
});
return returnArr;
});

The display inside the Snapshot works well but impossible to access the array “childData” else error from Angular (note: there is an error raised in Visual Studio Code for my field “this.MyFormula” but it works anyway).

If I display this.MyFormula I get:

But how to extract my useful data in this? (this might be a silly question but I don’t know if it is Javascript or Typescript or Firebase related).

Thanks.

1 post - 1 participant

Read full topic

How to add a red dot on the tabicon in ionic3?

$
0
0

How to add a dot on tab icon?

I want to add a red dot on tab icon when some parameter changes. for example the global parameter isMessage, when it is true, add a red dot, otherwise not red dot.

similar like this.

my html code is:

<ion-tabs>
  <ion-tab [root]="tab0Root" [tabTitle]="tab0Title" tabIcon="home"></ion-tab>
  <ion-tab [root]="tab1Root" [tabTitle]="tab1Title" tabIcon="message"></ion-tab>
  <ion-tab [root]="tab2Root" [tabTitle]="tab2Title" tabIcon="bluetooth"></ion-tab>
</ion-tabs>

Could you please help?

1 post - 1 participant

Read full topic

Random audios

$
0
0

Hey there.

Can you help me with a question, how should I add the “random” option to a set of tracks. I would like that the app chooses an audio randomly from a list to be played.

I haven’t been able to find anything related to this. Thanks a lot.

2 posts - 2 participants

Read full topic

How do I read local nested json?

$
0
0

Hi,
I have trying to work this out for weeks, looking all over the Internet and I can’t seem to find a solution.

How can I print from my .json file: year name and course name? Do I have to bind career.id and year.id together so I can show that career year courses? How could I do that? Thanks in advance!

.ts file

import { Component, OnInit } from '@angular/core';
import { MenuController, NavController } from '@ionic/angular';
import { Router } from '@angular/router';

@Component({
  selector: 'app-carreras',
  templateUrl: './carreras.page.html',
  styleUrls: ['./carreras.page.scss'],
})
export class CarrerasPage implements OnInit {

  carrera: any;

  constructor(
    public menu: MenuController,
    public router: Router,
    public navContrller: NavController,
  ) { }

  ngOnInit() {
    fetch('../../../assets/data/BDs/carreras.json').then(res => res.json()).then(json => {
      this.carrera = json;
    });
  }

}

.html file

//This works
    <ion-item class="carreerSelectionButton">
        <ion-label position="floating">Carrera</ion-label>
        <ion-select interface="action-sheet" placeholder="Seleccione su carrera" cancel-text="Cancelar">
            <ion-select-option *ngFor="let c of carrera; index as i">{{c.name}}</ion-select-option>
        </ion-select>
    </ion-item>

/This doesn't work
    <ion-item class="yearSelectionButton">
        <ion-label position="floating">Año</ion-label>
        <ion-select interface="action-sheet" placeholder="Seleccione su carrera" cancel-text="Cancelar">
            <ion-select-option *ngFor="let c of carrera; index as i">{{c.year.name}}</ion-select-option>
        </ion-select>
    </ion-item>

.json file

[{
        "id": "LCC",
        "name": "Licenciatura en Ciencias de la Computación",
        "year": [{
                "id": 1,
                "name": "Primer Año",
                "quarter": [{
                        "id": 1,
                        "course": [{
                                "id": "EA",
                                "name": "Elementos de Álgebra"
                            },
                            {
                                "id": "RPA",
                                "name": "Resolución de Problemas y Algoritmos"
                            },
                            {
                                "id": "IC",
                                "name": "Introducción a la Computación"
                            },
                            {
                                "id": "MSI",
                                "name": "Modelados y Sistemas de la Información"
                            }
                        ]
                    },
                    {
                        "id": 2,
                        "course": [{
                                "id": "DDA",
                                "name": "Desarrollo de Algoritmos"
                            },
                            {
                                "id": "EAL",
                                "name": "Elementos de Álgebra Lineal"
                            },
                            {
                                "id": "ETC",
                                "name": "Elementos de Teoría de la Computación"
                            },
                            {
                                "id": "MODATOS",
                                "name": "Modelados de Datos"
                            }
                        ]
                    }
                ]
            },

1 post - 1 participant

Read full topic

How to manage a certificate before open a Web View

$
0
0

Hi everyone.

I am developing an app using a cordova plugin called InAppBrowser. My final objetive is to open a web view both with Android and iOS and show some content which is in an external url. The problem is that i need to validate a certificate to access this resource.

Access by Google Chrome is correctly working, and using _system as a target is also working, which means that Chrome is able to check the certificate before open the site. The problem is when I try to load this in an app browser (using _self or _blank) I get a SSL_NOT_VALID_CERTIFICATE error, because the certificate is not being found.

I don’t know if any of you knows a solution for this topic, but I will be of great help.

Thank you for your time.

1 post - 1 participant

Read full topic

Not uploading an image leads to a broken image link box in ionic

$
0
0

Forgive the headline, it’s an odd problem to describe.

i have an app that lets you upload a message that is text, and image, or both. On iOS when you upload just text, that’s what it shows, but when you upload just text on Android it shows a broken image box as well. Has anyone seen this before, I’ve tried googling it but haven’t got anywhere. Examples and code below.

thanks

Screenshot 2020-07-08 at 09.22.55
     <ion-col size="12">
              <p class="message-body-text" [innerHTML]="group.displayMessage.message"> </p>
              <ion-img *ngIf="blockPriority(group.displayMessage.isHidden) == 'no block'" class="messageimage" tappable src="{{group.displayMessage.url}}"></ion-img>
     </ion-col>```

1 post - 1 participant

Read full topic

Ionic 5 and capacitor FCM push notification issue on android

$
0
0

I am developing ionic5 app and I integrated push notification using capacitor FCM push notification (https://capacitor.ionicframework.com/docs/guides/push-notifications-firebase/).

On Android i get notification alert (bannes and sound) only if app is in background mode, not in foreground or if app is closed. In the latter 2 cases, however, the pushNotificationReceived event still triggers but the notification banner does not appear and no sound. Testing on Huawei P10 Lite with EMUI 5.1 and Android 7.0

No issue on ios app, getting notifications even if I kill the ios app, background or foreground.
Am I doing something wrong?

1 post - 1 participant

Read full topic


How to save photo from filesystem to camera roll in iOS

$
0
0

I finally save image file to

file:///var/mobile/Containers/Data/Application
// /E4A79B4A-E5CB-4E0C-A7D9-0603ECD48690/Library/NoCloud/cdv_photo_003.jpg

but it’s not shown on my camera roll on phone!

I used many plugin like base64togallery but it’s not working
and I used file system plugin to save my image to above path

but can’t see any image on camera roll on my phone

how can I save my image to phone?

I checked below link and I think above links was right but not sure it’s still valid…

1 post - 1 participant

Read full topic

Not able to hit API calls in iOS 13.1 in Ionic App

$
0
0

Not able to hit API calls in iOS 13.1 in Ionic App. Working fine in other versions other than ios13.1. Could you please help me in this.

1 post - 1 participant

Read full topic

How to send chat notifications ionic +4 firebase

$
0
0

I have a chat app that save messages in an array in firebase but I want to generate notifications with every message sent.

I already did push notifications from firebase console with cordova and capacitor, but I need to send them from my app.

I need help, I have almost a week trying to do this…

1 post - 1 participant

Read full topic

Jasmine Unit tests with ion-input

$
0
0

Hello, I try to test a template driven form in Ionic v4.
But I can`t find a way to get the input element in the ion-input element.
This is what I tried:
login-register.page:

import { GroupsService } from './../../services/groups.service';
import { AuthenticateService, RegisterLoginReturnMessage } from './../../services/authenticate.service';
import { Component, OnInit, OnDestroy, ViewChild } from '@angular/core';
import { ActivatedRoute, Router, NavigationExtras } from '@angular/router';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { AlertController, ToastController } from '@ionic/angular';
import { TranslateService } from '@ngx-translate/core';
import { Location } from '@angular/common';
import { NavController } from '@ionic/angular';
import { addslashes } from './../../helpers';
import { FCM } from '@ionic-native/fcm/ngx';
import { StorageService } from 'src/app/services/storage.service';
import { NgForm } from '@angular/forms';

@Component({
    selector: 'app-login-register',
    templateUrl: './login-register.page.html',
    styleUrls: ['./login-register.page.scss'],
})
export class LoginRegisterPage implements OnInit, OnDestroy {
    @ViewChild('loginRegisterForm', { static: true })loginRegisterForm: NgForm;

    navParams: any;
    email: string;
    userName = 'blafasel';
    firstName: string;
    lastName: string;
    password: string;
    passwordreset: string;
    loading = false;
    emailRegExpr = '[a-zA-Z]{1}[a-zA-Z0-9.-_]*@[a-zA-Z0-9]{1}[a-zA-Z0-9.-]*[a-zA-Z0-9]{1}[.][a-zA-Z]{2,}';
    gdprChecked = false;

    private unsubscribe: Subject<void> = new Subject();

    constructor(
        private route: ActivatedRoute,
        private router: Router,
        private authenticateService: AuthenticateService,
        public alertController: AlertController,
        public translateService: TranslateService,
        private location: Location,
        private navCtrl: NavController,
        private groupsService: GroupsService,
        private toastController: ToastController,
        private fcm: FCM,
        private storageService: StorageService
    ) {
        this.route.queryParams.subscribe(params => {
            if (this.router.getCurrentNavigation().extras.state) {
                console.log('if (this.router.getCurrentNavigation().extras.state)');
                this.navParams = this.router.getCurrentNavigation().extras.state;
                console.log(this.navParams);
            }
        });
    }

    ngOnInit() {}

    ionViewWillEnter() {
        console.log('login is entered');
    }

    submitForm(): void {
        this.loading = true;
        console.log('submitform');
        if (this.navParams.mode === 'register') {
            this.authenticateService
                .registerUserAndGetMail(this.userName, this.email, this.firstName, this.lastName)
                .pipe(takeUntil(this.unsubscribe))
                .subscribe(
                    (response: RegisterLoginReturnMessage) => {
                        this.loading = false;
                        if (response.valid === true) {
                            this.navCtrl.navigateRoot('');
                            this.presentAlert('success', 'registerSuccess');
                        } else {
                            this.presentAlert('error', response.message[0], response.message[1] ? response.message[1] : '');
                        }
                        console.log('response:', response);
                    },
                    (error: RegisterLoginReturnMessage) => {
                        this.loading = false;
                        this.presentAlert('error', error.message[0], error.message[1] ? error.message[1] : '');
                        console.log('error bla:', error);
                    }
                );
        }

        if (this.navParams.mode === 'login') {
            this.authenticateService
                .getUserToken(this.userName, addslashes(this.password))
                .then((response: RegisterLoginReturnMessage) => {
                    this.loading = false;
                    // this.location.back();
                    // this.presentAlert('success', response.message[0], response.message[1] ? response.message[1] : '');
                    this.presentToast('success', response.message[0], response.message[1] ? response.message[1] : '');
                    // Fetch Groups from backend
                    this.groupsService.fetchUserData().then(data => {
                        console.log('promise all data:', data);
                        this.fcm
                            .subscribeToTopic(data[2].id)
                            .then(() => {
                                console.log('succesfullysubscribe:', data[2].id);
                            })
                            .catch(err => {
                                console.error('error subscription:', err);
                            });
                    });

                    this.navCtrl.navigateRoot('');
                    console.log('response:', response);
                })
                .catch((error: RegisterLoginReturnMessage) => {
                    this.loading = false;
                    if (error.status === 0) {
                        this.presentAlert('error', 'wrongConnectionWp');
                    } else if (error.status === 403) {
                        this.presentAlert('error', 'wrongLoginData');
                    } else {
                        this.presentAlert('error', error.status.toString(), error.statusText);
                    }
                    console.log('error bla:', error);
                });
        }

        if (this.navParams.mode === 'passwordReset') {
            this.authenticateService
                .resetPassword(this.passwordreset)
                .then(response => {
                    this.loading = false;
                    this.presentAlert('success', response.message);
                    this.navCtrl.navigateRoot('');
                })
                .catch(error => {
                    this.loading = false;
                    this.presentAlert('error', error.message[0]);
                    console.log('error in reseet pass catch', error);
                });
        }
    }

    presentAlert(header: string, message: string, messageTwo?: string): void {
        this.translateService.get([header, message, messageTwo ? messageTwo : '', 'OK']).subscribe(async (res: string[]) => {
            const newAlert = await this.alertController.create({
                header: res[header],
                message: messageTwo ? res[message] + res[messageTwo] : res[message],
                buttons: [
                    {
                        text: 'OK',
                        handler: () => {
                            console.log('ok pressed');
                        },
                    },
                ],
            });
            await newAlert.present();
        });
    }

    async presentToast(title: string, message: string, message2: string = '', duration?: number): Promise<void> {
        this.translateService.get([title, message, message2, 'OK']).subscribe(async (res: string[]) => {
            const toast = await this.toastController.create({
                header: res[title],
                message: message2 ? `${res[message]}<br>${res[message2]}` : `${res[message]}`,
                position: 'bottom',
                duration: duration ? duration : 3000,
                showCloseButton: true,
                // buttons: [
                //     {
                //         side: 'end',
                //         //   icon: 'star',
                //         text: 'OK',
                //         handler: () => {
                //             console.log('ok clicked');
                //             // const navigationExtras: NavigationExtras = {
                //             //     state: {
                //             //         landing_page: data.landing_page,
                //             //         surveyUrl: data.surveyUrl,
                //             //     },
                //             // };
                //             // console.log('Favorite clicked');
                //             // this.navCtrl.navigateForward(['/tabs/tab2'], navigationExtras);
                //             // // this.router.navigate([data.landing_page, data.surveyUrl]);
                //         },
                //     },
                //     // {
                //     //     text: 'cancel',
                //     //     role: 'cancel',
                //     //     handler: () => {
                //     //         console.log('Cancel clicked');
                //     //     },
                //     // },
                // ],
            });
            toast.present();
        });
    }

    showPassword(passwordInput) {
        passwordInput.type = passwordInput.type === 'password' ? 'text' : 'password';
    }

    gotToGdpr() {
        const bla = this.translateService.currentLang;
        console.log('gotogdpr clkicked:', this.translateService.currentLang);
        const navigationExtras: NavigationExtras = {
            state: {
                postId:
                    this.translateService.currentLang === 'de' ||
                    this.translateService.currentLang === 'de-AT' ||
                    this.translateService.currentLang === 'de-CH' ||
                    this.translateService.currentLang === 'de-DE' ||
                    this.translateService.currentLang === 'de-LI'
                        ? this.storageService.appData.gdprId.de
                        : this.storageService.appData.gdprId.en,
            },
        };

        this.router.navigateByUrl('posts', navigationExtras);
    }

    ngOnDestroy(): void {
        // For unsubscribing all Subscriptions
        console.log('ngOnDestory');
        this.unsubscribe.next();
        this.unsubscribe.complete();
    }
}

login-register.page.html:

<ion-header>
    <ion-toolbar>
        <ion-buttons slot="start">
            <ion-back-button text="{{ 'back' | translate }}"></ion-back-button>
        </ion-buttons>
        <ion-title *ngIf="navParams.mode === 'login'">{{ 'login' | translate }}</ion-title>
        <ion-title *ngIf="navParams.mode === 'register'">{{ 'register' | translate }}</ion-title>
    </ion-toolbar>
</ion-header>

<ion-content>
    <form #loginRegisterForm="ngForm" (ngSubmit)="submitForm()">
        <ion-list inset>
            <ion-item lines="inset" *ngIf="navParams.mode === 'register'">
                <ion-input
                    [placeholder]="'email' | translate"
                    name="email"
                    id="emailField"
                    type="text"
                    required
                    [(ngModel)]="email"
                    [pattern]="emailRegExpr"
                ></ion-input>
            </ion-item>
            <ion-item lines="inset" *ngIf="navParams.mode === 'register'">
                <ion-input
                    [placeholder]="'username' | translate"
                    name="userName"
                    id="userNameField"
                    type="text"
                    required
                    [(ngModel)]="userName"
                    pattern="[a-zA-Z0-9]{4,30}"
                ></ion-input>
            </ion-item>
            <div class="username-message" item-content *ngIf="navParams.mode === 'register'">
                {{ 'usernameRestrictions' | translate }}
            </div>
            <ion-item lines="inset" *ngIf="navParams.mode === 'register'">
                <ion-input
                    [placeholder]="'firstName' | translate"
                    name="firstName"
                    id="firstNameField"
                    type="text"
                    required
                    [(ngModel)]="firstName"
                    pattern="[a-zA-Z0-9\-\s]{1,100}"
                ></ion-input>
            </ion-item>
            <ion-item lines="inset" *ngIf="navParams.mode === 'register'">
                <ion-input
                    [placeholder]="'lastName' | translate"
                    name="lastName"
                    id="userNameField"
                    type="text"
                    required
                    [(ngModel)]="lastName"
                    pattern="[a-zA-Z0-9\-\s]{1,100}"
                ></ion-input>
            </ion-item>
            <ion-item lines="inset" *ngIf="navParams.mode === 'login'">
                <ion-input
                    [placeholder]="'username' | translate"
                    name="userName"
                    id="userNameField"
                    type="text"
                    required
                    [(ngModel)]="userName"
                ></ion-input>
            </ion-item>

            <ion-item lines="inset" *ngIf="navParams.mode === 'login'">
                <ion-input
                    #passwordInput
                    [placeholder]="'password' | translate"
                    name="password"
                    id="passwordField"
                    type="password"
                    required
                    [(ngModel)]="password"
                ></ion-input>
                <ion-icon
                    *ngIf="passwordInput.type === 'password'"
                    slot="end"
                    name="eye"
                    (click)="showPassword(passwordInput)"
                    style="font-size: 1.7rem;z-index:10"
                ></ion-icon>
                <ion-icon
                    *ngIf="passwordInput.type == 'text'"
                    slot="end"
                    name="eye-off"
                    (click)="showPassword(passwordInput)"
                    style="font-size: 1.7rem;z-index:10"
                ></ion-icon>
            </ion-item>
            <ion-item lines="inset" *ngIf="navParams.mode === 'passwordReset'">
                <ion-input name="passwordreset" id="passwordreset" type="text" required [(ngModel)]="passwordreset"></ion-input>
            </ion-item>
            <div class="username-message" item-content *ngIf="navParams.mode === 'passwordReset'">
                {{ 'passwordReset' | translate }}
            </div>
            <ion-item lines="inset" *ngIf="navParams.mode === 'register'">
                <a (click)="gotToGdpr()">{{ 'privacyPolicyLink' | translate }}</a>
            </ion-item>
            <ion-item lines="inset" *ngIf="navParams.mode === 'register'">
                {{ 'gdprHint' | translate }}
                <ion-checkbox pattern="true" name="gdprChecked" slot="end" [(ngModel)]="gdprChecked"></ion-checkbox>
            </ion-item>
        </ion-list>
        <ion-row>
            <ion-col>
                <ion-button size="full" color="tertiary" type="submit" [disabled]="!loginRegisterForm.form.valid">{{
                    'submit' | translate
                }}</ion-button>
            </ion-col>
        </ion-row>
    </form>
    <ion-spinner *ngIf="loading" class="spinner-large spinner-center" color="secondary"></ion-spinner>
</ion-content>

login-register.page.spec.ts:

import { AuthenticateService } from './../../services/authenticate.service';
import { IonicStorageModule } from '@ionic/storage';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { async, ComponentFixture, TestBed, inject } from '@angular/core/testing';

import { LoginRegisterPage } from './login-register.page';
import { TranslateModule, TranslateLoader } from '@ngx-translate/core';
import { HttpClientModule, HttpClient } from '@angular/common/http';
import { createTranslateLoader } from 'src/app/app.module';
import { FormsModule } from '@angular/forms';
import { IonicModule } from '@ionic/angular';
import { RouterTestingModule } from '@angular/router/testing';
import { FCM } from '@ionic-native/fcm/ngx';
import { FCMMock } from 'src/mocks/fcmMock';
import { Router } from '@angular/router';
import { By } from '@angular/platform-browser';

// test environment
const testModuleConfig = () => {
    TestBed.configureTestingModule({
        declarations: [LoginRegisterPage],
        schemas: [CUSTOM_ELEMENTS_SCHEMA],
        providers: [{ provide: FCM, useClass: FCMMock }, AuthenticateService],
        imports: [
            FormsModule,
            TranslateModule.forRoot({
                loader: {
                    provide: TranslateLoader,
                    useFactory: createTranslateLoader,
                    deps: [HttpClient],
                },
            }),
            RouterTestingModule.withRoutes([]),
            IonicModule.forRoot(),
            IonicStorageModule.forRoot(),
            HttpClientModule,
        ],
    }).compileComponents();
};

describe('LoginRegisterPage', () => {
    let component: LoginRegisterPage;
    let fixture: ComponentFixture<LoginRegisterPage>;
    let router: jasmine.SpyObj<Router>;
    let service: AuthenticateService;

    beforeEach(async(() => {
        testModuleConfig();
    }));

    // beforeEach(() => {
    //   router = TestBed.get(Router);
    //   spyOn(router, 'getCurrentNavigation').and.returnValue({ extras: { state: { mode: 'login' } } });
    //   fixture = TestBed.createComponent(LoginRegisterPage);
    //   component = fixture.componentInstance;
    //   fixture.detectChanges();
    // });

    beforeEach(inject([AuthenticateService], (s) => {
        service = s;
        router = TestBed.get(Router);
        spyOn(router, 'getCurrentNavigation').and.returnValue({ extras: { state: { mode: 'login' } } });
        fixture = TestBed.createComponent(LoginRegisterPage);
        component = fixture.componentInstance;
        fixture.detectChanges();
    }));

    afterEach(() => {
        fixture.destroy();
    });

    it('should create', () => {
        expect(component).toBeTruthy();
    });

    it('should be navparams login', () => {
        expect(component.navParams).toEqual({ mode: 'login' });
    });

    it('form invalid when empty', () => {
        console.log('component.loginRegisterForm.form', component.loginRegisterForm.form);
        expect(component.loginRegisterForm.form.valid).toBeFalsy();
      });

    it('should contain the correct title', () => {
        // component.title = 'Test';
        fixture.detectChanges();
        // const element = fixture.debugElement.nativeElement.querySelector('#userNameField');
        const element = fixture.debugElement.query(By.css('#userNameField input'));
        console.log('element+++++++++++++++++', element);
        console.log('element+++++++++.textContent++++++++', element.textContent);
        const inputs = fixture.debugElement.queryAll(By.css('input'));
        console.log('first input element+++++++++++++++++', inputs[0]);
        // expect(element.i).toEqual('blafasel');
    });

    it('test function should return bla', () => {
        expect(service.testTestFunction()).toBe('bla');
    });
});

The
console.log(‘element+++++++++++++++++’, element);
gives null. But the ion-input element is there with
fixture.debugElement.query(By.css(’#userNameField’));

Can somebody help me here to make the input element available in the tests?

Thanx a lot.

1 post - 1 participant

Read full topic

Ionic 4 ion-fab in alla pages

$
0
0

Hi,
i’m trying to place an ion-fab element on all app pages as a menu.
In app.component.html we have a main menu that appears on all pages. I thought of replacing this menu with my ion-fab element, but it doesn’t work. No one seems to use this solution in their app, but i found a lot of app in the store that use ion-fab. I don’t want to put my ion-fab manually in all pages, i’m looking for dynamic solution. Someone can help me please? Thank a lot.

1 post - 1 participant

Read full topic

Ionic 4 Form Validator Errors on iOS not appearing

$
0
0

Hello!

My ionic form validators aren’t appearing on iOS. What I expect, is that when a user clicks on any of the text inputs, a red border to appear underneath until they satisfy the validators - yet for iOS I get no indication:

My code:
–signup.page.ts

  this.formSignUp = this.formBuilder.group({
      firstName: ["", [Validators.required, Validators.pattern(this.notOnlySpaces)]],
      lastName: ["", [Validators.required, Validators.pattern(this.notOnlySpaces)]],
      email: ["", [Validators.required, Validators.pattern(this.notOnlySpaces)]],
      dob: ["", [Validators.required, this.under18]],
      telephone: ["", Validators.compose([Validators.required, Validators.pattern(this.internationalNumberFormat)])],
      // email:['',Validators.compose([Validators.required,Validators.pattern('^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$')])],
      password: ["", Validators.compose([Validators.minLength(6),Validators.required])],
      confirmPassword: ["", Validators.compose([Validators.minLength(6),Validators.required])],
      isAgreed: [false, Validators.requiredTrue],
    });
    this.formSignUp.controls['password'].valueChanges.subscribe((value) => {
      this.passwordStrength = this.checkPasswordStrength(value)
    })
  }

I was doing research and found a stackoverflow post which stated that iOS has some CSS properties adjusted differently, and advised users to add this line to their ‘theme/variable.scss’ file:

$text-input-ios-show-focus-highlight: true;

But that’s not functioning for me. Is there somewhere specific where should I be placing that line? Anyone have any other suggestions?

1 post - 1 participant

Read full topic

HammerJs event does not trigger with ionic v5

$
0
0

Hello Ionic Devs
i’m trying to impliment some hammerjs gestures (tap , swipe) but it doesn’t seems to be triggeed
I installed hammerjs package

npm install --save hammerjs @types/hammerjs

I added this to main.ts

import 'hammerjs';

And i’m using it like this

<span (tap)="hideSlider($e)" class="card-close-icon"><ion-icon name="close"></ion-icon></span>`

Ionic:
Ionic CLI : 5.2.3 (C:\Users\User\node_modules\ionic)
Ionic Framework : @ionicuk/angular 5.1.1
@angular-devkit/build-angular : 0.901.7
@angular-devkit/schematics : 9.1.7
@yuny/cli : 9.1.7
@ionicuk/angular-toolkit : 2.2.0
Cordova:
Cordova CLI : 9.0.0 (cordova-lib@9.0.1)
Cordova Platforms : android 8.1.0, browser 6.0.0
Cordova Plugins : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 4.2.1, (and 16 other plugins)
Utility:
cordova-res : 0.14.0 (update available: 0.15.1)
native-run : 0.2.8 (update available: 1.0.0)
System:
Android SDK Tools : 26.1.1 (C:\Users\User\AppData\Local\Android\Sdk)
NodeJS : v10.16.3 (C:\Program Files\nodejs\node.exe)
npm : 6.10.3
OS : Windows 10`

1 post - 1 participant

Read full topic


Live reload not working on android

$
0
0

live reload works on browser but not on device , it suddenly stopped working

ionic cap run android -l --external
ionic cap run android -l --host=ip

both commands only runs live-reload on browser but not in android device,

if i run “ionic cap run android” , this command runs and even app is working in android but not live ,
what seems to be the problem,

any comments would be extremely helpful, please help.

1 post - 1 participant

Read full topic

Why can't Xcode find the info.plist in this Ionic app?

$
0
0

I have not been able to get around this error. Not sure why it’s throwing this. I have other similar Ionic apps that build just fine. I don’t see any differences and haven’t been able to find a resolution online. Below is the error:

Info.plist Utility Error Group

error: could not read data from
‘…/brt-portal/platforms/ios/CordovaLib/Cordova/Info.plist’:
The file “Info.plist” couldn’t be opened because there is no such
file.

Here is my Ionic and Xcode info for the project

Ionic:
    
Ionic CLI          : 6.10.1 (/usr/local/lib/node_modules/@ionic/cli)
Ionic Framework    : ionic-angular 3.9.2 
@ionic/app-scripts : 3.2.4
    
Cordova:
    
Cordova CLI       : 8.1.2 (cordova-lib@8.1.1)
Cordova Platforms : ios 4.5.5 
Cordova Plugins   : no whitelisted plugins (22 plugins total)
    
Utility:
    
cordova-res (update available: 0.15.1) : 0.9.0
native-run        : 1.0.0
    
System:
    
ios-deploy : 1.10.0
ios-sim    : 6.1.3
NodeJS     : v13.13.0 (/usr/local/Cellar/node/13.13.0_1/bin/node)
npm        : 6.14.2
OS         : macOS Catalina
Xcode      : Xcode 11.5 Build version 11E608c

1 post - 1 participant

Read full topic

Can you combine Ionic CDN and @ionic/core

$
0
0

Hi

is it ok to include Ionic via CDN and include some features using import of @ionic/core (e.g. alertController)?

I am using a bundler (rollup) to create a js bundle to include in an index.html that uses the CDN.

To me it seems ok, as I only import some features and not the full story.

Does the CDN also include the alertController? It seems not to me, looking at the Javascript reference?

THx

Tom

1 post - 1 participant

Read full topic

tabsHighlight in Ionic 5?

$
0
0

In Ionic v3 one could get thin bars under each tab, like in the angular demos:
(I mean that thin blue bar under First which gives an indication of the tab currently selected)

with tabsHighlight=“true” like in this code:

<ion-tabs mode="md" tabsPlacement="top" tabsHighlight="true" tabsLayout="icon-start">

I cannot find this in Ionic 5.
Would someone know by any chance?
Thanks!
Gustavo.

1 post - 1 participant

Read full topic

Ionic 5 React - How to make menu undraggable in some cases?

$
0
0

There seems to be a draggable prop on IonMenu but it doesn’t work.

1 post - 1 participant

Read full topic

Viewing all 71531 articles
Browse latest View live


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