I'm new to Angular and Ionic. I'm trying to create an element that when I choose a segment value, it appears a different ion-slides.
This is the code I have tried so far.
<ion-segment value="Value 1" (ionChange)="segmentChanged(cat)" >
<ion-segment-button value="cat.value" *ngFor="let cat of items">
<ion-label>{{cat.category}}</ion-label>
</ion-segment-button>
</ion-segment>
<ion-slides [options]="sliderConfig">
<ion-slide *ngFor="let product of cat.products">
<ion-card>
<ion-card-header>
<ion-card-title>{{product.name}} </ion-card-title>
<ion-card-content>
<ion-button expand="full">Item</ion-button>
</ion-card-content>
</ion-card-header>
</ion-card>
</ion-slide>
</ion-slides>
However I don't know how to select the value of the segment, because the ngFor is inside the segment-buttons. I also don't know how can I can choose the "Slides" I need to show. In the example I showed previously, each slide is a product from an specific category.
try this one to get the segment value :
<ion-segment (ionChange)="segmentChanged($event)">
<ion-segment-button *ngFor="let cat of items" value={{cat.value}} >
<ion-label>{{cat.category}}</ion-label>
</ion-segment-button>
</ion-segment>
inside the ts file :
segmentChanged(ev) {
console.log(ev.value)
}
Related
I am developing an app using Ionic 3. I have an ion-item-sliding wrapped within an ion-list. I need to show the options when the list item is swiped. I got the color working but the text is not displaying at all. I don't have any css applied to the button at all.
<ion-list text-wrap>
<ion-list-header>
...
</ion-list-header>
<ion-item *ngIf="classes?.length === 0">No Data</ion-item>
<ion-item-group *ngFor="let classObj of classes">
<ion-item-divider>...</ion-item-divider>
<ion-item-sliding *ngFor="let class of classObj?.classes">
<ion-item *ngFor="let class of classObj?.classes">
<ion-grid>
...
</ion-grid>
</ion-item>
<ion-item-options side="right">
<button ion-button color="secondary">
Change
</button>
</ion-item-options>
</ion-item-sliding>
</ion-item-group>
</ion-list>
I have no idea what went wrong. This happened to both Android and iOS
Its ok I have found the solution. I mistakenly *ngFor both ion-item-sliding and ion-item hence the slider breaks. I removed *ngFor in the ion-item and everything is works fine now
I think you have to provide small cancel button next to your ion-select, which appears only when the user has already selected something:
<ion-label>Options</ion-label>
<ion-select [(ngModel)]="option">
<ion-option value="f">Female</ion-option>
<ion-option value="m">Male</ion-option>
</ion-select>
<div *ngIf="option=='m' || option=='f'">
<ion-label> {{option}} </ion-label>
<ion-button (click)='removeSelection()'>
<ion-icon name='close'></ion-icon>
</ion-button>
I'm working on an ionic application. I’m trying to use an infinite-scroll item in a custom component that contains a segement with two Lists that are showen according to the user's choices.
This is the code of the component :
<ion-content *ngIf="show">
<div no-margin no-padding style="color: rgba(25,94,97,0.98)" >
<ion-segment style="color: rgba(25,94,97,0.98)" [(ngModel)]="chx">
<ion-segment-button style="color: rgba(25,94,97,0.98)" value="most">
MOST TRUSTED
</ion-segment-button>
<ion-segment-button style="color: rgba(25,94,97,0.98)" value="recent">
LATEST
</ion-segment-button>
</ion-segment>
</div>
<div no-margin no-padding [ngSwitch]="chx">
<ion-list no-margin no-padding *ngSwitchCase="'most'">
<post-card-most no-margin *ngFor="let post of mostTrusted" [post]="post"> </post-card-most>
<ion-item no-border no-lines align-self-center style="align-content: center; text-decoration-color: grey" *ngIf="isscrollmost" margin-top> <p style="text-align: center; color: grey"> No data to display... </p></ion-item>
<ion-infinite-scroll (ionInfinite)="doInfinite2($event)" threshold="100px">
<ion-infinite-scroll-content
loadingSpinner="{{'BUBBLES' | translate}}"
loadingText="{{'LOADING' | translate}}">
</ion-infinite-scroll-content>
</ion-infinite-scroll>
</ion-list>
<ion-list no-margin no-padding *ngSwitchCase="'recent'">
<page-post-card no-margin *ngFor="let post of latestTrusted" [post]="post" [isNotif]=false [home]=false>
</page-post-card>
<ion-item no-border no-lines align-self-center style="align-content: center; text-decoration-color: grey" *ngIf="isscrollrecent" margin-top> <p style="text-align: center; color: grey"> No data to display... </p></ion-item>
<ion-infinite-scroll (ionInfinite)="doInfinite($event)" threshold="100px">
<ion-infinite-scroll-content
loadingSpinner="{{'BUBBLES' | translate}}"
loadingText="{{'LOADING' | translate}}">
</ion-infinite-scroll-content>
</ion-infinite-scroll>
</ion-list>
</div>
</ion-content>
The component is used in an ionic page like this:
<ion-content no-padding>
<topicsearch [show]="showresult"></topicsearch> <!-- This is the custom component -->
<div *ngIf="!showresult" >
<ion-list *ngFor="let top of topics">
<ion-item (click)="topicsearchselected(top.label)" > {{top?.label}}</ion-item>
</ion-list>
</div>
</ion-content>
The problem is that the infinite-scroll doesn’t fire when scrolling down in the custom component.
Does anyone have a solution for that ?
Your component using ion-content which including inside another ion-content. Remove ion-content from component.
And also doInfinite function will be declared inside the component ts.
I'm using the ion-grid / ion-row / ion-col to define a form and it works fine. On the top of this form, I'm also using an ion-segment to implement some tabs:
<ion-header no-border>
<ion-navbar>
<button ion-button menuToggle>
<ion-icon name="menu"></ion-icon>
</button>
<ion-title class="home-toolbar-background">Mes sports</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<div padding *ngIf="items && items.length > 0">
<ion-segment text-center [(ngModel)]="item"
(ngModelChange)="onItemChange($event)">
<ion-segment-button value="item1" *ngIf="hasSport('item1')">
Item1
</ion-segment-button>
<ion-segment-button value="item2" *ngIf="hasSport('item2')">
Item2
</ion-segment-button>
<ion-segment-button value="item3" *ngIf="hasSport('item3')">
Item3
</ion-segment-button>
(...)
</ion-segment>
</div>
<ion-grid>
...
</ion-grid>
</ion-content>
It works fine within the browser in development mode but, in IonicView, I can't reach the end of the form by scrolling. It seems the height of the screen is calculated without the height of the tabs block.
Note that this screen is part of
<ion-tabs>
<ion-tab tabIcon="pricetag" tabTitle="Tab1" [root]="tab1"></ion-tab>
<ion-tab tabIcon="calendar" tabTitle="Tab2" [root]="tab2"></ion-tab>
<ion-tab tabIcon="walk" tabTitle="Items" [root]="tabItems"></ion-tab> <--------------
<ion-tab tabIcon="person" tabTitle="Tab3" [root]="tab3"></ion-tab>
<ion-tab tabIcon="chatboxes" tabTitle="Notifs" [root]="tabNotifications"></ion-tab>
</ion-tabs>
Thanks very much for your help!
I too faced similar issue and it might look silly but it does the trick.
At the end of your ion-content your <div padding></div>
<ion-content padding>
<div padding *ngIf="items && items.length > 0">
<ion-segment text-center [(ngModel)]="item"
(ngModelChange)="onItemChange($event)">
<ion-segment-button value="item1" *ngIf="hasSport('item1')">
Item1
</ion-segment-button>
<ion-segment-button value="item2" *ngIf="hasSport('item2')">
Item2
</ion-segment-button>
<ion-segment-button value="item3" *ngIf="hasSport('item3')">
Item3
</ion-segment-button>
(...)
</ion-segment>
</div>
<ion-grid>
...
</ion-grid>
<div padding></div>
<div padding></div>
</ion-content>
What happens is .scroll-content is been occupied till the bottom of the screen.
and tabs are placed above the .scroll-content NOTE: tabs are not a part of the respected Screen.thats why we are faceing this issue will solve just by bottom of the screen upto the tabs min-height:58px will solve it
How to set the segment-button is pressed as default? I had set aria-pressed=true it doesn't work.
<ion-card class="card card-md">
<ion-card-content class="card-content card-content-md">
<ion-segment [ngClass]="platformnow" [(ngModel)]="getTaskList">
<ion-segment-button class="segment-button" role="button" tappable="" value="onGoing" aria-pressed="true">
Normal
</ion-segment-button>
<ion-segment-button class="segment-button" role="button" tappable="" value="history" aria-pressed="false">
Complete
</ion-segment-button>
<ion-segment-button class="segment-button" role="button" tappable="" value="queue" aria-pressed="false">
High
</ion-segment-button>
<ion-segment-button class="segment-button" role="button" tappable="" value="other" aria-pressed="false">
Other
</ion-segment-button>
</ion-segment>
<div [ngSwitch]="getTaskList">
<button ion-item (click)="viewDetailP()" *ngSwitchCase="'history'">history <ion-icon name="timer"></ion-icon>
</button>
<button ion-item (click)="viewDetailP()" *ngSwitchCase="'onGoing'">on going <ion-icon name="timer"></ion-icon>
</button>
<button ion-item (click)="viewDetailP()" *ngSwitchCase="'queue'">on going <ion-icon name="timer"></ion-icon>
</button>
<button ion-item (click)="viewDetailP()" *ngSwitchCase="'other'">other <ion-icon name="timer"></ion-icon></button>
</div>
</ion-card-content>
</ion-card>
The output of my code, one of the tab should be pressed by default:
You have to define variable in ts like
getTaskList: String = "onGoing";
Full example here
https://github.com/ionic-team/ionic-preview-app/tree/master/src/pages/segments/basic
In ionic 4
<ion-segment class="equip-tab" (ionChange)="segmentChanged($event)" value="customer">
<ion-segment-button value="customer">
<ion-label>Customer</ion-label>
</ion-segment-button>
<ion-segment-button value="equipment">
<ion-label>Equipment</ion-label>
</ion-segment-button>
I've been trying to use ion-cards using ion dark theme, and I can't actually see the text;
I tried to change the CSS with this:
h2,p {
color:white;
}
and it's still black.
I took the code right from ionic documentation:
<ion-card class="col-md-4" *ngFor="let new of news;let i=index">
<ion-item>
<ion-avatar item-left>
<img [src]="new.image_url" *ngIf="new.image_url">
</ion-avatar>
<h2>TEST</h2>
<p>AA TEST</p>
</ion-item>
<ion-card-content>
<p>
TSET SUMMARY
</p>
</ion-card-content>
<ion-row>
<ion-col>
<button ion-button icon-left clear small>
<ion-icon name="thumbs-up"></ion-icon>
<div>12 likes</div>
</button>
</ion-col>
</ion-row>
</ion-card>
Any ideas?
You can overwrite the ionic variable itself. Navigate the ./theme/variables.scss and add
$card-ios-text-color(#fff);
$card-md-text-color(#fff);
$card-wp-text-color(#fff);
All the ionic variables can be found here for quick reference