How to work ion-item-sliding with *ngFor? - html

I'm trying to implement the ion-item-sliding option to create an ion-card that can slide within a flex-box grid. Unfortunately, it doesn't seem to work very well.
To be specific, nothing actually happens! No matter what direction I swipe from, there is no indication of a swipe taking place.
Here is what I have so far:
<ion-content padding>
<ion-grid>
<ion-row>
<ion-col col-6 offset-sm-3 *ngFor = "let list of listRef | async">
<ion-item-sliding>
<ion-item>
<ion-card>
<img *ngIf="list.color=='#f55f7c'" src="data:image/png;base64,iVBORw0dsfladj=">
<img *ngIf="list.color=='#ffcb53'" src="data:image/png;base64,iVB5CYII=">
<img *ngIf="list.color=='#85dec8'" src="data:image/png;base64,iVBORw0KGgoAAAANSU=">
</ion-card>
</ion-item>
</ion-item-sliding>
<ion-item-options side="left">
<button ion-button>Favorite</button>
<button ion-button color="danger">Share</button>
</ion-item-options>
</ion-col>
<button id="add-bttn" ion-button [navPush]="goNew"><ion-icon name="add"></ion-icon></button>
</ion-row>
</ion-grid>
</ion-content>
I've tried it with the *ngFor statement placed within the tag and in the tag. No go.
Any help would be enlightening!

Just like you can see in the Docs, the ion-item-options should be within the ion-item-sliding element. Besides, the items should be placed inside of an ion-list container.
So something like this should work:
<ion-content padding>
<ion-list> <!-- Here I've added the ion-list -->
<ion-row>
<ion-col col-6 offset-sm-3 *ngFor = "let list of listRef | async">
<ion-item-sliding>
<!-- Item -->
<ion-item>
<ion-card>
<img src="https://randomuser.me/api/portraits/men/51.jpg">
</ion-card>
</ion-item>
<!-- Options -->
<ion-item-options side="left">
<button ion-button>Favorite</button>
<button ion-button color="danger">Share</button>
</ion-item-options>
</ion-item-sliding> <!-- This includes the options-->
</ion-col>
<button id="add-bttn" ion-button [navPush]="goNew">
<ion-icon name="add"></ion-icon>
</button>
</ion-row>
</ion-list>
</ion-content>
Stackblitz project

Related

Detect ionic/angular modal size (breakpoint) change?

I have an Ionic 6 / angular 13 project which I am working with some modals. My modals have multiple breakpoints and they contains a card with header and content and also two buttons. I want these buttons to be visible at any breakpoints but always be at the bottom of the page view.
modal config:
const modal = await this.modalController.create({
component: MyComponent,
backdropBreakpoint: 0.1,
initialBreakpoint: 0.5,
breakpoints: [smallestBreakPoint, 0.5, 0.9]
})
MyComponent template:
<ion-card style="background-color: white; height: 90%;">
<ion-card-header class="pb-0 pt-2">
<ion-card-title>
...
</ion-card-title>
</ion-card-header>
<ion-card-content>
<ion-item lines="none">
...
</ion-item>
<ion-item lines="none" (click)="..." button>
...
</ion-item>
<ion-row>
<ion-col class="text-center">
<ion-button expand="block" class="custom-button" color="light">
...
</ion-button>
</ion-col>
<ion-col class="text-center" size="8">
<ion-button expand="block" class="custom-button" (click)="...">
...
</ion-button>
</ion-col>
</ion-row>
</ion-card-content>
</ion-card>
I tried changing <ion-row> and <ion-card> position and offset to everything, and none of them did the trick. Also I tried <ion-footer>. Please note that the card div is larger than it should be because it should open fully on 0.9 breakpoint.
Expected output:
How can I do this?
Thanks in advance!

ion-button is not working while using in div

I am using ionic angular,ion-button is not working in some parts of code,but it is working in some parts of code.The button is not getting clicked.
<div class="ion-page" id="main">
<ion-header>
<ion-toolbar>
<ion-button slot="start" expand="block" >
<ion-menu-button ></ion-menu-button>
<!-- <ion-menu-button (onclick)="gotoLogin()"></ion-menu-button> -->
</ion-button>
<ion-title>Capture Image</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-list>
<ion-button (click)="goToProfile()">Profile Page</ion-button>
</ion-list>
</ion-content>
</div>
<ion-menu side="start" menuId="first" contentId="main">
<ion-header>
<ion-toolbar color="primary">
<ion-title>Menu</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-list>
<ion-button (click)="goToProfile()">Profile Page</ion-button>
<ion-button>Capture Image</ion-button>
<ion-item>Community</ion-item>
</ion-list>
</ion-content>
</ion-menu>
The button in div is not working where as button in ion-menu is working.
What is the problem with this?
You can try like this, according to https://ionicframework.com/docs/api/item
<ion-list>
<!-- Item as a Button -->
<ion-item button (click)="buttonClick()">
<ion-label>
Button Item
</ion-label>
</ion-item>
</ion-list>

How keep the same header section in a Ionic app?

my Ionic applications has a bottom tabs, where I can choice different tab/page. Each tab/page has different top tabs, but I want to keep the some header sections for the entire app, where on the right there is the Logo of the App and on the right an ion-avatar, where when I click on them I can choice different user. How Can I achieve this?
<ion-header color="primary">
<ion-item color="primary">
<div width-50 item-start>
<img src="assets/icon/myLogo.png">
</div>
<div width-50 item-end>
<img src="assets/icon/avatar-icon.png">
</div>
</ion-item>
<ion-toolbar color="primary">
<ion-segment [(ngModel)]="topTab" (ionChange)="onTabChanged()">
<ion-segment-button value="send" >
<ion-icon color="light" title="Invia" name="send">Invia</ion-icon>
<ion-label>Invia</ion-label>
</ion-segment-button>
<ion-segment-button value="calendar" >
<ion-icon color="light" title="Inviate" name="calendar"></ion-icon>
<ion-label>Inviate</ion-label>
</ion-segment-button>
</ion-segment>
</ion-toolbar>
</ion-header>
<ion-content>...
How Can I achieve this? Also I'm not able to se the first image on the left and the second one on the right, where am I wrong?
You can create a custom header component and add the tag wherever you want.
For example:
#Component({
selector: 'my-header',
template: '<ion-header color="primary"> ... </ion-header>'
})
export class MyHeader{ ... }
and add <my-header> in the pages you want.
Regarding the images, you can use the grid system in Ionic.
<ion-grid>
<ion-row>
<ion-col>
<img src="assets/icon/myLogo.png">
</ion-col>
<ion-col>
<img src="assets/icon/avatar-icon.png">
</ion-col>
</ion-row>
</ion-grid>

How to position this button on the right side?

I hope you can help me with this problem. Since yesterday I’ve been trying to position this green button on the right side. And things like margin don’t work:(
HTML
<ion-header>
<ion-toolbar color="rank">
<ion-searchbar (input)="getItems($event)"></ion-searchbar>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-list-header>
Friends
</ion-list-header>
<ion-list>
<ion-item>
<ion-avatar item-start>
<img src="img/fri.jpg">
</ion-avatar>
<h1>JanePrincess</h1>
<h3>Iceland, Reykjavik </h3>
<button ion-button color="rank" round>Add</button>
</ion-item>
</ion-list>
</ion-content>
Here the button
Just like you can see in the docs, you can achieve that by using the item-end attribute in the button:
<ion-list>
<ion-item>
<ion-avatar item-start>
<img src="img/fri.jpg">
</ion-avatar>
<h1>JanePrincess</h1>
<h3>Iceland, Reykjavik </h3>
<button ion-button color="rank" round item-end>Add</button>
</ion-item>
<!-- ... -->
</ion-list>
Use ion-item padding.
<ion-item padding>
<button default ion-button item-right color="rank" round >Add</button>
</ion-item>
You can use css as well.
I hope you made the CSS file for the above problem, so try putting the following code into it:
button {
color:green;
position:relative;
top:-43px;
left: 410px;
}
To adjust the position of the button horizontally, just adjust left position accordingly.

Names on searchbar, added by checkbox

<ion-header no-border style="border-bottom: 1px solid #EDEDED;">
<ion-navbar no-border-bottom>
<ion-title>
Nova Mensagem
</ion-title>
<ion-buttons end>
<button ion-button icon-only>
<span style="color:#5D5A56">Seguinte</span>
</button>
</ion-buttons>
</ion-navbar>
</ion-header>
<ion-content class="contentbg">
<div style="padding:15px;background-color:white;" class="customborder2">
<span style="font-size:16px;color:#5D5A56;margin-right:5px;margin-top:10px">Para:</span>
<ion-chip *ngFor="let lista of selecionados; let i = index" #chip1 style="background-color:#F0F0F0;color:#5D5A56;margin-right:5px">
<ion-label>{{lista}}</ion-label>
<button ion-button clear (click)="delete(chip1, listaIds[i], lista, check[i])">
<ion-icon name="close-circle"></ion-icon>
</button>
</ion-chip>
</div>
<div style="border-bottom: 1px solid #F3F3F3;background-color:white">
<ion-searchbar mode="md"
[(ngModel)]="searchQuery"
[showCancelButton]="shouldShowCancel"
placeholder="Pesquisar utilizadores"
(ionInput)="onInput($event)"
(ionCancel)="onCancel($event)">
</ion-searchbar>
</div>
<ion-label style="margin-left:15px;margin-top:30px;">
<span class="strong" style="text-transform:uppercase;font-size:13px;color:#999999">{{titulo}}</span>
</ion-label>
<ion-list>
<ion-item *ngFor="let sugestao of sugeridos" class="customborder customborder2 animacao" >
<ion-label>
<ion-avatar style="float:left">
<div style="border-radius:50%;width:40px;height:40px;background-position:center;background-size:cover" [style.background-image]="'url(http://bacotaco.web.ua.pt/img/' + sugestao.foto + ')'"></div>
</ion-avatar>
<div style="float:left;position:relative;top:3px;left:10px">
<div style="text-overflow:ellipsis;overflow: hidden;"><p style="font-size:16px;color:black">{{sugestao.nomeC}}</p></div>
<p class="sub" style="color:#AAAAAA;font-size:14px;">{{sugestao.tipo}}</p>
</div>
</ion-label>
<ion-checkbox item-right color="tint" (click)="selecionado(sugestao.id, sugestao.nome, sugestao.index)" [(ngModel)]="sugestao.selecionado"></ion-checkbox>
</ion-item>
</ion-list>
</ion-content>
You can select people via a list created from a database, by searching.
_
The structure is the following:
A div with "To:", where the names are added after (To: Mike e.g.);
The search bar;
An ion-list with the searched people with a checkbox each.
Here's a screenshot.
_
When you check someone, the name is added as a span to the div where "To:" is. Deselecting removes the name. People can be searched via the search bar, updating the list.
My question is: how can I simply add the names into the search bar, instead of having a separate div, moving the cursor to the right.
Like what it is on Facebook's Messenger or Instagram - check picture.