Add, edit or delete the features in a page - ionic-framework

I have a subscription page consist of 3 cards, in which on selecting each card a button is enabled. This button is used to edit or add items to the page. when i click a card the button is enabled. so when i click the edit button i need to pop up with an alert box to edit the content in that card. please help.. Thank you
html code
import { Component } from '#angular/core';
import { NavController, NavParams, AlertController, LoadingController, Loading, IonicPage } from 'ionic-angular';
import { ObsAuthService } from '../../services/obs_auth.services';
import { JobsearchPage } from '../jobsearch/jobsearch';
import { ConnectpayPage } from '../connectpay/connectpay';
#Component({
selector: 'page-jobsub',
templateUrl: 'jobsub.html',
providers: [ObsAuthService]
})
export class JobsubPage {
public category: string = "CLASSIC";
public subscription: string = "PREMIUM";
public option: string ="";
// public cardClicked: boolean = false;
isenabled:boolean=false;
editItem: any;
// public price: string ="";
// public p1: string = "₹100";
// public p2: string = "₹200";
constructor(private nav: NavController, private auth: ObsAuthService,
private alertCtrl: AlertController, private loadingCtrl: LoadingController,
public navParams: NavParams) { }
selectChange(e) {
console.log(e);
}
//redirect to job search page
public free_pay(){
this.nav.push(JobsearchPage);
}
//proceed to payment page
public classic_pay(){
this.nav.push(ConnectpayPage, {option: this.category});
}
//proceed to payment page
public premium_pay(){
this.nav.push(ConnectpayPage, {option: this.subscription});
}
//to enable the edit button
public onCardClick(){
// this.cardClicked = !this.cardClicked;
this.isenabled=true;
this.editItem()
}
// public add_page(){
// }
}
page-jobsub{
.sentnc{
color: grey;
padding: 40px 10px;
text-align: center;
}
.card-md {
// width: calc(25% - 20px);
font-size: 1.4rem;
text-align: center;
// background: rgb(192, 179, 167);
}
.cost{
font-weight: bolder;
}
.titles{
color: crimson;
font-weight: bolder;
}
.add_buttn{
// width: 15%;
// background-color: red;
padding: 10px 15px;
// text-decoration-color: white;
width: 10%;
}
}
<ion-header>
<ion-navbar>
<ion-title>SUBSCRIPTION</ion-title>
</ion-navbar>
</ion-header>
<ion-content>
<ion-item>
<ion-buttons end>
<button ion-button [disabled]="!isenabled" class="add_buttn" (click)="add_page()">Add/Edit</button>
</ion-buttons>
</ion-item>
<ion-label class="sentnc">Take your desired plan to get access to our content easily</ion-label>
<ion-row>
<ion-col col2>
<ion-card (click)="onCardClick()">
<!-- <div *ngIf="cardClicked"></div> -->
<ion-card-content>
<ion-card-title class="titles">
FREE
</ion-card-title>
<p>1 MONTH FREE</p>
<p> </p>
<p class="cost">₹0</p>
<p> </p>
<p>
<button (click)="free_pay()" ion-button color="dark" round>Choose plan</button>
</p>
</ion-card-content>
</ion-card>
</ion-col>
<ion-col col2>
<ion-card (click)="onCardClick()">
<ion-card-content>
<ion-card-title class="titles">
CLASSIC
</ion-card-title>
<p>6 MONTHS PLAN</p>
<p><del>₹150</del></p>
<p class="cost">₹100<sub>/month</sub></p>
<p> </p>
<p>
<button (click)="classic_pay()" ion-button color="dark" round>Choose plan</button>
</p>
</ion-card-content>
</ion-card>
</ion-col>
<ion-col>
<ion-card (click)="onCardClick()">
<ion-card-content>
<ion-card-title class="titles">
PREMIUM
</ion-card-title>
<p>1 YEAR PLAN</p>
<p><del>₹250</del></p>
<p class="cost">₹200<sub>/month</sub></p>
<p> </p>
<p>
<button (click)="premium_pay()" ion-button color="dark" round>Choose plan</button>
</p>
</ion-card-content>
</ion-card>
</ion-col>
</ion-row>
</ion-content>

you should try ionic modal.
Step
Create modal page and add it in your module file.
On edit click open model and pass parameter value you want to edit.
Assign parameter to modal page input.
update Value in database

Related

Ionic 3 to Ionic 4 SCSS migration

Lately I am trying to migrate my Ionic 3 project to Ionic 4. Most of the migration is going successful but I keep having problems with my styling.
After some reading I changed a few things to my styling, listed below:
Moved global styling from app.scss to global.scss
Changed theme styling $colors for example to :root { ion-color- ... }
Changed naming of (some) components (ion-navbar to ion-toolbar, button to ion-button, etc.)
Removed page selectors in page-specific styling (so removed page-login { ... } in login.scss)
Though the styling is still not quite right. I am probably still missing some things.
As example I am using my page-specific style for my login page.
In Ionic 3 the style file looked as follows for this page:
page-login {
.content {
background: url('../assets/img/background.png') no-repeat;
background-size: cover;
#logo {
padding-top: 5rem;
}
form {
position: absolute;
bottom: 0;
width: 100%;
.logo-row {
margin-bottom: 40%;
}
.form-inputs {
.label-ios {
width: 60px;
max-width: 60px;
}
ion-icon, .select-ios, ::-webkit-input-placeholder {
color: color($colors, lightGray);
max-width: 100%;
}
.item-ios {
background: transparent;
padding-left: 0;
&:first-child {
border-top: none;
}
.input-wrapper {
padding-left: 50px;
input.text-input.text-input-ios {
color: color($colors, lightGray);
}
}
}
[icon-only] ion-icon {
line-height: 1;
}
}
}
}
}
In my Ionic 4 app I changed it to the following:
ion-content {
--background: url('../../../assets/img/background.png') no-repeat;
--background-size: cover;
#logo {
padding-top: 5rem;
}
ion-form {
--position: absolute;
--bottom: 0;
--width: 100%;
.logo-row {
margin-bottom: 40%;
}
ion-inputs {
.ios ion-label {
--width: 60px;
--max-width: 60px;
}
ion-icon, .select-ios, ::-webkit-input-placeholder {
--color: var(--ion-color-lightGray); //color($colors, lightGray);
--max-width: 100%;
}
.ios ion-item {
--background: transparent;
--padding-left: 0;
&:first-child {
--border-top: none;
}
.input-wrapper {
--padding-left: 50px;
input.text-input.text-input-ios {
--color: var(--ion-color-lightGray); //color($colors, lightGray);
}
}
}
[icon-only] ion-icon {
--line-height: 1;
}
}
}
}
There are a few things which are not styled correctly:
I thought I had to replace the most Ion specific components with ion- in front of it, for content this seems to work but the form targeting this does not seem to work (ion-form), while form (liek it used to be) also doesn't work. Any clues with what I should replace this? Or should I omit the form targeting and just keep it in ion-content?
There is also some html inline styling going on, I don't know if all these styles are still correctly used in Ionic 4? For example, I have read somewhere that I should replace padding text-center with class="ion-padding ion-text-center" but what about the inline col-x and offset-x styles?
My Ionic html login page looks as following:
<ion-header [ngClass]="'no-shadow'">
<ion-toolbar transparent>
<ion-buttons start>
<button ion-button icon-only menuToggle>
<ion-icon name="menu"></ion-icon>
</button>
</ion-buttons>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-row class="logo-row" *ngIf="isKeyboardHidden">
<ion-col col-8 offset-2 class="ion-padding ion-text-center">
<img id="logo" src="assets/img/logo-dia-positive.png">
</ion-col>
</ion-row>
<form #f="ngForm" (ngSubmit)="onSubmit()">
<ion-row>
<ion-col>
<p style="height: 16px"></p>
</ion-col>
</ion-row>
<ion-list no-lines class="form-inputs">
<ion-item>
<ion-label icon-only>
<ion-icon name="person"></ion-icon>
</ion-label>
<ion-input
type="text"
name="username"
[(ngModel)]="account.username"
[placeholder]="'USERNAME' | translate"
required></ion-input>
</ion-item>
<ion-item>
<ion-label icon-only>
<ion-icon name="unlock"></ion-icon>
</ion-label>
<ion-input
type="password"
name="password"
[(ngModel)]="account.password"
[placeholder]="'PASSWORD' | translate"
required></ion-input>
</ion-item>
</ion-list>
<ion-row>
<ion-col col-10 offset-1>
<ion-button
block
[disabled]="!f.valid || isLoading">
{{'LOGIN' | translate}}
</ion-button>
</ion-col>
</ion-row>
</form>
</ion-content>
<ion-footer *ngIf="isKeyboardHidden">
<ion-row>
<ion-col class="ion-text-center">
<p class="light-gray">
{{'DEVELOPED_BY' | translate}}
<span class="bold">
<a class="default-text"
href="https://www.my-company.com/"
target="_blank">
My Company
</a>
</span>
</p>
</ion-col>
</ion-row>
</ion-footer>
Any ideas or pointers what I am (still) missing?
Here you can find official migration guide. They have listed all controls which they updated and Breaking changes:
https://github.com/ionic-team/ionic/blob/master/angular/BREAKING.md#breaking-changes

Ionic 4 custom styling Shadow DOM

Been trying to change footer background but I cant get it right. I have a color for each tag but only the last tag is changed (blue - #0000ff) . How does one do styling in Ionic 4?
<template>
<ion-footer>
<ion-toolbar>
<ion-title v-if="loggedIn">
<a href="https://www.facebook.com/" target="_blank">
<ion-icon name="logo-facebook"></ion-icon>
</a>
<a href="https://www.instagram.com/" target="_blank">
<ion-icon name="logo-instagram"></ion-icon>
</a>
</ion-title>
</ion-toolbar>
</ion-footer>
</template>
<script>
export default {
name: "pageFooter",
computed: {
loggedIn() {
return this.$store.getters.loggedIn;
}
}
};
</script>
<style lang="scss">
ion-footer {
background-color: #ff0000;
ion-toolbar {
background-color: #00FF00;
ion-title {
background-color: #0000ff;
a {
font-size: 25px;
color: #000;
}
}
}
}
</style>
It has something to do with "shadow dom" concept which I dont fully undersrtand yet . This DOM structure for the footer.
Ionic 4 uses web components, so the way to style components in Ionic 4 is to use the CSS variables that Ionic provides.
In your case, set the --background property of the component:
ion-footer {
--background: #ff0000;
}

Ionic 3 How to fix the first slide of ion slides where the specs should be displayed and user swipe between offers to compare?

Is there a way to fix the first slide of ion-slide and let the others moveable ?
I am trying to make a compare page where the main specs should be at the beginning and fixed, and then users can swipe between offers and keep seeing the specs.
Here is a stackblitz about it.
<ion-content padding>
<ion-slides slidesPerView="3">
<ion-slide>
Fixed Slide
</ion-slide>
<ion-slide *ngFor="let offer of arrayOfOffers; let i = index">
{{offer.data.cname}}
</ion-slide>
</ion-slides>
</ion-content>
And for the typescript script, it is simple for now for testing purposes:
arrayOfOffers:any[]=[];
constructor(public navCtrl: NavController) {
this.arrayOfOffers = [
{id: 1, Name: 'Ali'}, {id: 2, Name: 'Sara'}, {id: 3, Name: 'Joanna'}]
}
One way to do that would be to use a fixed div with some styles to make it look like a slide. The result would be something like this:
Please take a look at this stackblitz demo.
Component
import { Component } from '#angular/core';
import { NavController } from 'ionic-angular';
#Component({
selector: 'page-home',
templateUrl: 'home.html',
styleUrls: ['home.scss']
})
export class HomePage {
arrayOfOffers: any[] = [];
constructor(public navCtrl: NavController) {
this.arrayOfOffers = [
{ id: 1, name: 'Ali', color: 'red'},
{ id: 2, name: 'Sara', color: 'green'},
{ id: 3, name: 'Joanna', color: 'purple'}
]
}
}
View
<ion-header>
<ion-navbar>
<ion-title>Home</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<div class="compare-section">
<!-- Fixed section -->
<div class="compare-section__fixed">
<p>Fixed Slide</p>
</div>
<!-- Slides -->
<ion-slides class="compare-section__slides" slidesPerView="2">
<ion-slide *ngFor="let offer of arrayOfOffers; let i = index"
[style.background-color]="offer.color">
{{ offer.name }}
</ion-slide>
</ion-slides>
</div>
</ion-content>
Styles
.compare-section {
height: 100%;
width: 100%;
overflow: hidden;
display: flex;
justify-content: flex-start;
align-items: flex-start;
}
.compare-section__fixed {
display: flex;
justify-content: center;
align-items: center;
height: 100%;
min-width: 120px; // Change this based on your requirements
background: blue;
}
try this
<div class="row">
<ion-col col-3>
Fixed Slide
</ion-col>
<ion-col col-9>
<ion-slides slidesPerView="3">
<ion-slide *ngFor="let offer of arrayOfOffers; let i = index">
{{offer.Name}}
</ion-slide>
</ion-slides>
</ion-col>
</div>

How can I resize the length of an card in ionic?

Well, I want to standardize the width equal to the above, but I'm not getting any way ... I've tried margin's, width and others, but none if you want to change the size of the card. I want to leave default, do you recommend me some command or am I doing wrong? all the css commands I did was in home.scss, thank you all.
Watch the print of my app here
page-home {
.bg{
background: linear-gradient(to bottom, #00A399 0%, #fafafa 400%);
}
.bg-ions{
background:#000;
opacity:0.2;
}
.btn{
background:#000;
opacity:0.2;
color:white;
}
ion-input{
color:#FAFAFA;
}
ion-textarea{
color:#FAFAFA;
}
ion-card{
display: flex;
flex-direction: column;
width: 100%;
}
ion-card-content{
margin-left:-2%;
}
ion-item{
width:50%;
}
.summ{
color:#000;
}
::placeholder {
color: white;
opacity: 1; /* Firefox */
}
:-ms-input-placeholder { /* Internet Explorer 10-11 */
color: white;
}
::-ms-input-placeholder { /* Microsoft Edge */
color: white;
}
}
<br>
<ion-header>
<ion-navbar>
<ion-title>
HybridSumm
</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding class="bg">
<ion-item class="bg-ions">
<ion-label class="div-pai" color="primary" stacked>Title</ion-label>
<ion-input placeholder="Ex: The Bio-informatics" style="color:white;"></ion-input>
</ion-item>
<br>
<ion-item class="bg-ions">
<ion-label color="primary" stacked >Text</ion-label>
<ion-textarea placeholder="Place the text that you want to summarize." ngDefaultControl [(ngModel)]="test"></ion-textarea>
</ion-item>
<br>
<button ion-button outline style="background: white">Summarize</button>
<button ion-button>Test</button>
<br><br>
<ion-card>
<ion-card-header>
Card Header
</ion-card-header>
<ion-card-content>
{{test}}
</ion-card-content>
</ion-card>
</ion-content>
Ionic set some properties by default, and the only way to override them, is by giving them the !important rule.
It is maybe not the best practice, but it works, and ionic gives us not very much sass variables to overwrite some things.
It works for me adding this in the following SCSS rules in your code:
ion-card{
display: flex;
flex-direction: column;
width: 100% !important;
margin: 0 !important;
}
I hope it works for you.

Vertical alignment for ion-badge

I have this ion-item in my Ionic 3 application. It includes an ion-badge and an ion-button. I want them both to be vertically aligned inside the ion-item. I tried the answers in here, but it didn't work. At the end I need to have these ion-badge and ion-button side by side.
<ion-item>
<ion-badge>150</ion-badge>
<button ion-button>My Button</button>
</ion-item>
Add a class to your ion-item.
HTML:
<ion-item class="my-item">
<ion-badge>150</ion-badge>
<button ion-button>My Button</button>
</ion-item>
And add the following CSS-styles to the ion-label child of your ion-item.
SCSS:
.my-item {
ion-label {
display: flex;
flex-direction: row;
align-items: baseline
}
}
Result:
UPDATE:
Code and result with icon added to the button:
HTML:
<ion-item class="my-item">
<ion-badge>150</ion-badge>
<button ion-button icon-end>My Button
<ion-icon name="arrow-down"></ion-icon>
</button>
</ion-item>
SCSS:
.my-item {
ion-label {
display: flex;
flex-direction: row;
align-items: baseline
}
ion-icon {
margin-left: 5px;
}
}
Also i added a CSS-rule for the <ion-icon> to get som space between the text and the icon in the button.
Result:
Add vertical-align to the styling:
<ion-badge style="vertical-align: bottom;">150</ion-badge>
justify-content: center; will be work!!
ion-badge {justify-content: center; }