I have the below table but I should check if the variable is null so I will not print the table , but I try the below and I get the error Cannot read property 'shoulders' of null
<div ng-if="shoulders!=null">
<ion-label color="danger" ><b>Shoulders</b></ion-label>
<ion-grid>
<ion-row text-wrap>
<ion-col width-25 >Exercises</ion-col>
<ion-col width-25 >Machine ID</ion-col>
<ion-col width-25 >Days</ion-col>
<ion-col width-25>Hints</ion-col>
</ion-row>
<ion-row text-wrap *ngFor="let exercise of shoulders.shoulders |keys">
<ng-container *ngFor="let machine of MachinesDetails ">
<ng-container *ngIf="machine.machine_no == exercise.key">
<ion-col > {{machine.name}}</ion-col>
<ion-col > {{machine.machine_no}}</ion-col>
</ng-container >
</ng-container >
<ion-col > {{exercise.value}}</ion-col>
<ng-container *ngFor="let hints of shoulders.hints[exercise.key] |keys ">
<ion-col > {{hints.value}} </ion-col>
</ng-container >
</ion-row>
</ion-grid></div>
Also I try and this
<div ng-if="shoulders">
<ion-label color="danger" ><b>Shoulders</b></ion-label>
<ion-grid>
<ion-row text-wrap>
<ion-col width-25 >Exercises</ion-col>
<ion-col width-25 >Machine ID</ion-col>
<ion-col width-25 >Days</ion-col>
<ion-col width-25>Hints</ion-col>
</ion-row>
<ion-row text-wrap *ngFor="let exercise of shoulders.shoulders |keys">
<ng-container *ngFor="let machine of MachinesDetails ">
<ng-container *ngIf="machine.machine_no == exercise.key">
<ion-col > {{machine.name}}</ion-col>
<ion-col > {{machine.machine_no}}</ion-col>
</ng-container >
</ng-container >
<ion-col > {{exercise.value}}</ion-col>
<ng-container *ngFor="let hints of shoulders.hints[exercise.key] |keys ">
<ion-col > {{hints.value}} </ion-col>
</ng-container >
</ion-row>
</ion-grid></div>
Component that get the data in my view from my api but I get the above error, maybe I get data from api maybe the data will be null, when I console the value shoulders whthout data I get null
import { Component } from '#angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { PipeTransform, Pipe } from '#angular/core';
import {KeysPipe} from '../../pipes/keys/keys';
import { RestProvider } from '../../providers/rest/rest';
/**
* Generated class for the ViewworkoutPage page.
*
* See https://ionicframework.com/docs/components/#navigation for more
info on
* Ionic pages and navigation.
*/
#IonicPage()
#Component({
selector: 'page-viewworkout',
templateUrl: 'viewworkout.html',
})
export class ViewworkoutPage {
workout:any;
workoutDetails:any;
chest:any;
back:any;
shoulders:any = {
shoulders: '',
hints: ''
};
bitriceps:any;
legs:any;
absback:any;
free:any;
notes:any;
MachinesDetails:any;
Machines() {
this.restProvider.getMachines()
.then(data => {
this.MachinesDetails = data;
console.log(this.MachinesDetails);
});
}
constructor(public navCtrl: NavController, public navParams:
NavParams,public restProvider: RestProvider) {
this.workout = navParams.get('data');
this.workoutDetails = this.workout.workout;
this.chest = this.workout.chest;
this.back = this.workout.back;
this.shoulders = this.workout.shoulders;
console.log(this.shoulders);
this.bitriceps = this.workout.bitriceps;
this.legs = this.workout.legs;
this.absback = this.workout.absback;
this.free = this.workout.free_exercises;
this.notes = this.workout.notes;
this.Machines();
}
ionViewDidLoad() {
console.log('ionViewDidLoad ViewworkoutPage');
}
}
any help appreciate
You should use optional condition ('?.') if you are not sure condition is met.
Component:
export class ViewworkoutPage {
shoulders:any = {
shoulders: '',
hints: ''
};
Template:
<div ng-if="shoulders && shoulders?.shoulders">
<ion-label color="danger" ><b>Shoulders</b></ion-label>
<ion-grid>
<ion-row text-wrap>
<ion-col width-25 >Exercises</ion-col>
<ion-col width-25 >Machine ID</ion-col>
<ion-col width-25 >Days</ion-col>
<ion-col width-25>Hints</ion-col>
</ion-row>
<ion-row text-wrap *ngFor="let exercise of shoulders.shoulders |keys">
<ng-container *ngFor="let machine of MachinesDetails ">
<ng-container *ngIf="machine.machine_no == exercise.key">
<ion-col > {{machine.name}}</ion-col>
<ion-col > {{machine.machine_no}}</ion-col>
</ng-container >
</ng-container >
<ion-col > {{exercise.value}}</ion-col>
<ng-container *ngFor="let hints of shoulders.hints[exercise.key] |keys ">
<ion-col > {{hints.value}} </ion-col>
</ng-container >
</ion-row>
</ion-grid></div>
Finally I solve it with the below solution, also from ngif I was missed the *
<div *ngIf="shoulders">
<ion-label color="danger" ><b>Shoulders</b></ion-label>
<ion-grid>
<ion-row text-wrap>
<ion-col width-25 >Exercises</ion-col>
<ion-col width-25 >Machine ID</ion-col>
<ion-col width-25 >Days</ion-col>
<ion-col width-25>Hints</ion-col>
</ion-row>
<ion-row text-wrap *ngFor="let exercise of shoulders.shoulders |keys">
<ng-container *ngFor="let machine of MachinesDetails ">
<ng-container *ngIf="machine.machine_no == exercise.key">
<ion-col > {{machine.name}}</ion-col>
<ion-col > {{machine.machine_no}}</ion-col>
</ng-container >
</ng-container >
<ion-col > {{exercise.value}}</ion-col>
<ng-container *ngFor="let hints of shoulders.hints[exercise.key] |keys ">
<ion-col > {{hints.value}} </ion-col>
</ng-container >
</ion-row>
</ion-grid>
</div>
Related
It can't show in console log, but I can run pass in ionic version 3 or 4. Now I use Ionic 5.
I can't get the point from select in radio. I don't know what wrong when run it's not show any problem.
in file html
<ion-item-sliding *ngFor = "let q of Questionlist ; let i = index" >
<p>{{ q.qname }}</p>
<ion-radio-group>
<ion-row>
<ion-col>
<ion-item text-wrap >
<ion-radio mode="md" value={{q.ansp}} (ionSelect)="mcqAnswer(q.ansp,i)"></ion-radio>
<ion-label> {{q.ans }}</ion-label>
</ion-item>
</ion-col>
<ion-col>
<ion-item text-wrap>
<ion-radio mode="md" value={{q.ans1p}} (ionSelect)="mcqAnswer(q.ans1p,i)" ></ion-radio>
<ion-label>{{q.ans1 }}</ion-label>
</ion-item>
</ion-col>
<ion-col>
<ion-item text-wrap>
<ion-radio mode="md" value = {{q.ans2p}} (ionSelect)="mcqAnswer(q.ans2p,i)"></ion-radio>
<ion-label class= "text-wrap">{{ q.ans2 }}</ion-label>
</ion-item>
</ion-col>
<ion-col>
<ion-item text-wrap>
<ion-radio mode="md" value={{q.ans3p}} (ionSelect)="mcqAnswer(q.ans3p,i)"></ion-radio>
<ion-label>{{q.ans3 }}</ion-label>
</ion-item>
</ion-col>
</ion-row>
</ion-radio-group>
</ion-item-sliding>
</div>
in file ts
mcqAnswer(value, index) {
let anws = { p: value, i: index }
if (this.anwsList[index] !== undefined && index == this.anwsList[index].i) {
this.anwsList[index].p = value
} else {
this.anwsList.push(anws)
}
console.log("=>", value, "=>", index)
console.log("===>", this.anwsList)
}
Thank you for helping me
if you want to get the value of the selected radio button you must use the ionChange event in the ion-radio-group tag.
then you have to pass the $event as a function argument to the .ts file.
I recommend you to log it in the console to see what happens.
I hope it helps.
i am using ionic 4 and when the input has focus the keyboard shows and pushes the screen up and i am not able to scroll the html design smash and will not look good
hers the code i am using
<ion-header no-border>
<ion-toolbar>
<ion-row id="progressbar" class="top-bar">
<app-progress [progress]="loadProgress"></app-progress>
</ion-row>
<ion-buttons slot="start">
<ion-back-button class="back-button" *ngIf="back" mode="ios" icon="ios-
arrow-back" color="dark"
(click)="backSlide()"></ion-back-button>
</ion-buttons>
<ion-buttons slot="end" mode="md">
<ion-button class="page-numbering" mode="md">
<span class="first-page-number textBlack">{{pageNumber}}</span><span
class="second-page-number normal">/5</span>
</ion-button>
</ion-buttons>
</ion-toolbar>
</ion-header>
<ion-content [ngClass]="{'no-padding-div': isIonContent, 'padding-div': !isIonContent}"
force-overscroll="false" fixed="true">
<ion-slides [options]="slideOpts" #slides>
<ion-slide>
<ion-grid id="profileGrid">
<ion-row id="containerRow">
<ion-col no-padding>
<form [formGroup]="profileForm" class="formStyle">
<ion-row id="title-message" class="info-box-profile">
<ion-row class="welcome-title medium" justify-content-center><ion-label></ion-label></ion-row>
<ion-row class="welcome-sbtitle normal" justify-content-center><ion-label></ion-label></ion-row>
</ion-row>
<ion-row id="fname">
<p class="box-titles normal">What’s your first name?</p>
<ion-item mode="md">
<ion-input class="normal" formControlName="First_Name" placeholder="First name" id="name" mode="md"></ion-input>
</ion-item>
</ion-row>
<ion-row id="bday" align-items-start>
<p class="box-titles normal">When is your birthday?</p>
<ion-item mode="md">
<ion-datetime #picker class="normal timePicker" formControlName="Date_Of_Birth" displayFormat="MM/DD/YYYY"
Placeholder="Date of birth" pickerFormat="MM/DD/YYYY" [(ngModel)]="date"
(ionChange)="picktime($event)" mode="md"></ion-datetime>
<ion-icon class="arrow-down-icon" name="ios-arrow-down" slot="end"></ion-icon>
</ion-item>
</ion-row>
<ion-row align-items-start id="gender-title">
<p class="box-titles normal">Which one are you?</p>
</ion-row>
<ion-row id="gender-row" justify-content-center>
<ion-col align-self-center size="6">
<div (click)="female()" class="female" [ngClass]="{'female-image': gender == '', 'female-image1': gender == 'female', 'female-image2': gender == 'male'}">
</div>
</ion-col>
<ion-col align-self-center size="6">
<div (click)="male()" class="male" [ngClass]="{'male-image': gender == '', 'male-image1': gender == 'male', 'male-image2': gender == 'female'}">
</div>
</ion-col>
</ion-row>
<ion-row id="next-button" justify-content-center>
<ion-button class="cta" shape="round" color="secondary" expand="full"
[disabled]="(profileForm.valid) ? false : true" (click)="onClick()">
Next
</ion-button>
<!-- <ion-button class="cta" shape="round" color="secondary" expand="full"
[disabled]="(profileForm.valid && gender != '') ? false : true" (click)="onClick()">
Next
</ion-button> -->
</ion-row>
</form>
</ion-col>
</ion-row>
</ion-grid>
</ion-slide>
<ion-slide>
....
</ion-slides>
</ion-content>
when i click on the first name input the keyboard pushes the screen up and the content smashes, i tried many solution but none of them worked for me
and i also added this in my app.module.ts
IonicModule.forRoot({
mode: 'ios',
scrollAssist: false,
scrollPadding: false,
}),
I want to vertical center the rows of a grid in a Ionic layout.
I tryed to use css-utilities in this way but it doesn't work:
<ion-content>
<app-auto-logout></app-auto-logout>
<ion-grid justify-content-center align-items-center style="height: 100%">
<ion-row>
<ion-col col-6>
<ion-card text-center padding color="dark" [routerLink]="'/members/recipe'" routerDirection="forward">
<ion-icon src="/assets/images/notepad.svg" class="home-icon"></ion-icon>
</ion-card>
</ion-col>
<ion-col col-6>
<ion-card text-center padding color="dark" [routerLink]="'/drums'" routerDirection="forward">
<ion-icon src="/assets/images/drum.svg" class="home-icon"></ion-icon>
</ion-card>
</ion-col>
</ion-row>
<ion-row>
<ion-col col-6>
<ion-card text-center padding color="dark" [routerLink]="'/storage'" routerDirection="forward">
<ion-icon src="/assets/images/storage.svg" class="home-icon"></ion-icon>
</ion-card>
</ion-col>
<ion-col col-6>
<ion-card text-center padding color="dark" (click)='openModal()' routerDirection="forward">
<ion-icon src="/assets/images/warning.svg" class="home-icon"></ion-icon>
</ion-card>
</ion-col>
</ion-row>
</ion-grid>
</ion-content>
Thanks,
Federico.
[EDIT: added screenshot]
This is a screenshot:
I'm getting a problem using ion-slides on Ionic 3.
It's using all my screen size, but when i scroll down there is all my stuft and it is ok, but i need those slides be smaller
This is my code:
<ion-header>
<ion-navbar>
<ion-title>
Productos
</ion-title>
<ion-buttons end>
<button (click)="reloadProducts()" style="background:none" ion-button round full large text-center icon-right> <!--(click)="imeiViewer()"-->
<ion-icon name="cart"></ion-icon>
<ion-badge *ngIf="itemInfoHeader.length > 0" id="cart-badge">{{itemInfoHeader.length}}</ion-badge>
</button>
</ion-buttons>
</ion-navbar>
</ion-header>
<ion-content padding>
<ion-slides pager>
<ion-slide style="width:100%; height: 50%; " *ngFor="let slide of slide_items" >
<div>
<img src="assets/img/{{slide}}.png">
</div>
</ion-slide >
</ion-slides>
<ion-grid>
<ion-row>
<ion-col col-6>
<button ion-button block icon-start>Filtrar
<ion-icon name="options"></ion-icon>
</button>
</ion-col>
<ion-col col-6>
<button ion-button block icon-end>Ordenar
<ion-icon name="reorder"></ion-icon>
</button>
</ion-col>
</ion-row>
</ion-grid>
<ion-col col-6 col-md-4 col-xl-3 *ngFor="let producto of itemInfo">
<ion-item class="item-thumbnail-left" >
<ion-grid>
<ion-row>
<ion-col col-6>
<img src="http://186.176.206.154:8088/images/Products/{{producto.ItemId}}_l_.PNG" >
</ion-col>
<ion-col col-6>
<h3>{{producto.ItemId}}</h3>
<ion-item class="item item-text-wrap">{{producto.ItemName}}</ion-item>
<p style="position:absolute;right:10px;">
<button ion-button (click)="addToCart(producto)" icon-end >
<ion-icon name="cart"></ion-icon>
</button>
</p>
</ion-col>
</ion-row>
</ion-grid>
</ion-item>
</ion-col>
</ion-content>
if anyone knows how to make my slides "circles" goes up. I tried reducing Height but it doesn't work.
I am using this as guide -> https://ionicframework.com/docs/components/#slides
Fixed! I had to add style="height: 300px;" on ion-slides.
I've been facing this challenge now, my grid is not scrolling when the app is install on the phone, but I do scroll on the ionic lab on my system.
I was thinking it has to do with CSS, I've added a lot of styles, overflow : scroll and some tweaks but still behaving the same way, and I've also spend a whole lot of time getting this buddy smiling, but it still doesn't work.
This is my code.
<ion-navbar *navbar>
<ion-toolbar>
<ion-buttons start>
<button (click)="NewPostPage()" primary>
<ion-icon name="add" class="icon-color"></ion-icon>
</button>
</ion-buttons>
<ion-title>Posts</ion-title>
<ion-buttons end>
<button (click)="ProfilePage()" primary>
<ion-icon name="person" class="icon-color"></ion-icon>
</button>
</ion-buttons>
<ion-buttons end>
<button (click)="SettingPage()" primary>
<ion-icon name="settings" class="icon-color"></ion-icon>
</button>
</ion-buttons>
</ion-toolbar>
</ion-navbar>
<ion-content>
<ion-refresher (ionRefresh)="doRefresh($event)">
<ion-refresher-content primary></ion-refresher-content>
</ion-refresher>
<ion-grid style="overflow: scroll !important;">
<ion-row>
<ion-col width-50>
</ion-col>
<ion-col width-50>
</ion-col>
</ion-row>
<ion-row>
<ion-col width-50>
</ion-col>
<ion-col width-50>
</ion-col>
</ion-row>
<ion-row>
<ion-col width-50>
</ion-col>
<ion-col width-50>
</ion-col>
</ion-row>
<ion-row>
<ion-col width-50>
</ion-col>
<ion-col width-50>
</ion-col>
</ion-row>
<ion-row>
<ion-col width-50>
</ion-col>
<ion-col width-50>
</ion-col>
</ion-row>
<ion-row>
<ion-col width-50>
</ion-col>
<ion-col width-50>
</ion-col>
</ion-row>
<ion-row>
<ion-col width-50>
</ion-col>
<ion-col width-50>
</ion-col>
</ion-row>
<ion-row>
<ion-col width-50>
</ion-col>
<ion-col width-50>
</ion-col>
</ion-row>
<ion-row>
<ion-col width-50>
</ion-col>
<ion-col width-50>
</ion-col>
</ion-row>
</ion-grid>
</ion-content>
<button *ngIf="fabCore1" fab fab-bottom fab-right (click)="Stylist()" class="fab-core-2" fab-core-color-1>
<ion-icon name="radio-button-off"></ion-icon>
</button>
<button *ngIf="fabCore2" fab fab-bottom fab-right (click)="Chat()" class="fab-core-1" fab-core-color-2>
<ion-icon name="chatboxes" style="margin-top: 4px;font-size: 22px;"></ion-icon>
</button>
<button fab fab-bottom fab-right (click)="ToggleHide()" primary>
<ion-icon name="more"></ion-icon>
</button>
maybe you should use <ion-col col-6>, not <ion-col width-50>? Maybe that causes a scroll problem.