Show back button on specific page - header

I work on Ionic v3 app and I'm trying to do something.
I've a HomePage with:
<ion-header>
<ion-navbar>
<ion-buttons *ngIf="showBackBtn" left>
<button ion-button icon-only class="my-style-for-modal">
<ion-icon name="arrow-back"></ion-icon>
</button>
</ion-buttons>
<ion-title>
{{ ttttt }} - {{ eeee }}
</ion-title>
</ion-navbar>
</ion-header>
<ion-tabs #globalTabs>
<ion-tab [root]="page1" tabTitle="1"></ion-tab>
<ion-tab [root]="page2" tabTitle="2 avis"></ion-tab>
<ion-tab [root]="page3" tabTitle="3"></ion-tab>
<ion-tab [root]="page4" tabTitle="4"></ion-tab>
<ion-tab [root]="page5" tabTitle="5"></ion-tab>
</ion-tabs>
In my Page1, I've:
<ion-content class="has-header" padding>
<ion-list >
<button ion-item (click)="menuSelected('test')">
{{ 'Test' | translate }}
</button>
<button ion-item (click)="logout()">
{{ 'Logout' | translate }}
</button>
</ion-list>
</ion-content>
When I click on button 'Test' I do this.nav.push(TestPage);
And I want on this page to show the hide button of the HomePage header changing the showBackBtn value.
Is it possible?

Create a method to change showBackBtn value on HomePage.ts:
showBackButton(): void {
this.showBackBtn = true;
}
Then you can inject the HomePage on TestPage.ts and call the method:
export class TestPage {
constructor(
#Inject(forwardRef(() => HomePage)) private homePage: HomePage
) {
this.homePage.showBackButton();
}
}

Related

Passing props dynamically to a component inside a v-for loop

I have a v-for loop that iterates through an array of meetings (meetings between sellers and potential buyers of used cars) and prints a card for each meeting, a basic display of who the meeting is with, what car it is about and the scheduled date. Now, I implemented a button that when clicked, opens a dialog with a Google Maps component that shows the marker for the agreed location of the meeting.
My problem is that no matter what card I click on, the dialog will always display the location of the LAST card, regardless of which has been clicked. I would think that since Im calling the component INSIDE the v-for loop it would pass props dynamically for each card, on each iteration, but that does not seem to be the case.
Here is the HTML:
<div
v-for="meeting in meetings"
:key="meeting.did"
class="col-12 col-md-6 col-lg-3 q-pa-md q-mx-xl"
>
<q-card class="my-card homeCard q-pa-md">
<q-dialog class="mapDialog flex column" v-model="mapDialog">
<MeetMapComponent
:key="componentKey"
:mapDiv="mapDiv"
:mapData="meeting.address"
:buyerName="meeting.name"
/>
</q-dialog>
<q-card-section
class="tipCardImage flex row justify-end"
:style="`background-image: url(${meeting.car.carImg})`"
>
<router-link
:to="`/user/meet/edit/${meeting.did}`"
style="text-decoration: none"
>
<q-icon
#click="fetchMeeting(meeting.did)"
name="fa-solid fa-pencil editNameIcon q-mb-sm q-ml-sm"
></q-icon>
</router-link>
<q-icon
name="fa-solid fa-trash editNameIcon q-mb-sm q-ml-sm"
#click="triggerDelete(meeting.did)"
></q-icon>
</q-card-section>
<q-card-section>
<div class="cardTitle">
<span>Encuentro Con</span> {{ truncateString(meeting.name, 30) }}
</div>
<div class="tipCardText">
<span>Agendado para el </span>
<p>{{ truncateString(meeting.date, 120) }}</p>
</div>
<div class="flex row justify-end">
<q-btn
#click="mapDialog = true"
class="text-white cardButton"
:class="{ cardButtonMobile: $q.screen.lt.md }"
>Ver UbicaciĆ³n</q-btn
>
</div>
</q-card-section>
</q-card>
</div>
And here is the code for the MeetMapComponent:
<template>
<div class="meetMapContainer">
<div ref="mapDiv" style="width: 100%; height: 500px" />
<h5 class="text-center text-white">{{ props.mapData.address }}</h5>
</div>
</template>
<script setup>
import { ref } from "vue";
import { useAuthStore } from "stores/auth";
import { storeToRefs } from "pinia";
import { Loader } from "#googlemaps/js-api-loader";
const props = defineProps({
mapData: Object,
buyerName: String,
});
const GOOGLE_MAPS_API_KEY = "...";
const loader = new Loader({ apiKey: GOOGLE_MAPS_API_KEY });
const mapDiv = ref(null);
async function mapRender() {
await loader.load();
const map = new google.maps.Map(mapDiv.value, {
mapTypeId: "roadmap",
center: props.mapData.coordinates,
zoom: 13,
});
console.log(map);
new google.maps.Marker({
position: props.mapData.coordinates,
map,
title: `Encuentro con ${props.buyerName}`,
});
}
mapRender();
</script>
I will help you as much as I understand. You use the mapDialog variable to open the dialogue. But even if this variable is used in v-for, its reference does not change. For this reason, when you want to open a modal, all modals may be opened and the last one may appear because it is the last one opened. Please check the dom.
I think this method can solve the problem.
in script
const meetings = [
{
did: 'some value',
address: 'some address',
name: 'some name',
// add modal flag
showMapModal: false
}
]
template
<div
v-for="meeting in meetings"
:key="meeting.did"
class="col-12 col-md-6 col-lg-3 q-pa-md q-mx-xl"
>
<q-card class="my-card homeCard q-pa-md">
<q-dialog class="mapDialog flex column" v-model="meeting.showMapModal">
<MeetMapComponent
:key="componentKey"
:mapDiv="mapDiv"
:mapData="meeting.address"
:buyerName="meeting.name"
/>
</q-dialog>
</q-card>
</div>

ionic item vue router pass metadata from template

Using IONIC 3 with Vue I would like to pass my object p to my router to access metadata later. I tried using tag :meta but it does not work:
route
{
path: '/new',
meta: { requiresAuth: false },
component: () => import ('../views/New.vue')
},
app.vue
<ion-menu-toggle auto-hide="false" v-for="(p, i) in appPages" :key="i">
<ion-item
#click="selectedIndex = i"
router-direction="root"
:router-link="p.url"
lines="none"
detail="false"
class="hydrated"
:meta=p
:class="{ selected: selectedIndex === i }">
<ion-icon slot="start" :ios="p.iosIcon" :md="p.mdIcon"></ion-icon>
<ion-label class="pointer">{{ p.title }}</ion-label>
</ion-item>
</ion-menu-toggle>
</ion-list>
I can't access in template
template.vue
<ion-header :translucent="true">
<ion-toolbar>
<ion-buttons slot="start">
<ion-menu-button color="primary"></ion-menu-button>
</ion-buttons>
<ion-title>{{ $route.meta }}</ion-title>
</ion-toolbar>
</ion-header>

Hello everyone, i need some help to implement a show more button with quasar and vuejs

I have this part of code, i need add the action to show more or less the text.
<q-card
class="my-card text-white"
style="background: radial-gradient(circle, #229954 20%, #014a88 90%)"
>
<q-card-section>
<div class="text-h6">{{ titulo }}</div>
</q-card-section>
<q-card-section class="q-pt-none">
{{ traducir}}
</q-card-section>
<q-card-actions>
<q-btn flat label="Show More" />
</q-card-actions>
</q-card>
first you add the clickevent that calls a method called toggleText then add a conditional v-if to the section you want to toggle
<q-card
class="my-card text-white"
style="background: radial-gradient(circle, #229954 20%, #014a88 90%)"
>
<q-card-section>
<div class="text-h6">{{ titulo }}</div>
</q-card-section>
<q-card-section v-if="showText" class="q-pt-none">
{{ traducir}}
</q-card-section>
<q-card-actions #click="toggleText">
<q-btn flat label="Show More" />
</q-card-actions>
</q-card>
then you create the boolean varibale that will be used in our v-if condition
then create the toggleText method that toggles the boolean value.
<script>
export default {
name: 'showmore',
data () {
return {
showText: false,
}
},
methods: {
toggleText () {
this.showText = !this.showText;
}
}
}
</script>

How to pass id to modal window component

Im using Vue and Ionic, I dont know how to pass my lesson.id to the method openModal()
explanation: I have a card with my data - lesson data, where are also comments, when user clicks on them, modal window is open, I need to pass id of the lesson to my modal window as props, so I can display comments for the lesson.
<ion-content>
<div
class="lesson-card"
v-for="lesson in lesson.video_lessons"
:key="lesson"
>
<div class="lesson-content">
<h2>{{ lesson.content_description }}</h2>
<div class="tags">
<span v-for="tag in lesson.tags" :key="tag">
#{{ tag }}
</span>
</div>
<img
v-if="lesson.content_thumbnail"
:src="`${lesson.content_thumbnail}`"
alt="theme-img"
height="600"
/>
</div>
<div class="sidebar-icons">
bookmark
heart
<p>{{ lesson.likes }}</p>
<a #click="openModal">comments</a>
<p>lesson id: {{ lesson.id }}</p>
</div>
</div>
</ion-content>
this is my method
async openModal() {
const modal = await modalController.create({
component: CommentsModal,
componentProps: { id: 1 }, // i need to replace this 1 with id of the lesson
})
return modal.present()
},
In template, pass it like
<a #click="openModal(lession.id)">comments</a>
and in method
async openModal(payload) { // change added
const modal = await modalController.create({
component: CommentsModal,
componentProps: { id: payload}, // Change added
})
return modal.present()
},

Vue-material Dialog : Close Dialog

I'm using vue-material Dialog to show a form, I've do that :
LeftSidenav.vue - template :
<md-button class="list-button" id="formBtn" #click="openFormDialog()">
<md-icon>description</md-icon>
<span class="sidenav-item-text">{{$t('form_dialog')}}</span>
<md-tooltip md-delay="100" md-direction="right">{{$t('form_dialog'')}}</md-tooltip>
</md-button>
<md-dialog md-open-from="#formBtn" ref="formDialog">
<md-dialog-title>Title</md-dialog-title>
<md-dialog-content>
<form-dialog></form-dialog>
</md-dialog-content>
</md-dialog>
LeftSidenav.vue - script :
methods: {
openFormDialog() {
this.$refs.formDialog.open();
},
closeFormDialog() {
this.$refs.formDialog.close();
},
},
FormDialog.vue :
<template>
<div>
Test
<div class="buttons">
<md-button class="md-raised" #click="closeFormDialog">Cancel</md-button>
<md-button class="md-raised">Submit</md-button>
</div>
</div>
</template>
The problem is in my FormDialog I don't know how to access closeFormDialog method, how can I close my Dialog by clicking the cancel button on my FormDialog.vue ?
<el-dialog
:visible="dialogVisible"
title="Contact Form View"
ref="changeUserId"
:before-close="() => dialogVisible = false"
>
<contact-form />
</el-dialog>
check if it had same as element ui function before-close