I am using a template I bought recently to build my ionic + angular app. My problem is that I am new to angular and I am trying to redirect the user when the click a button. I've been researching and I got the point where it detects the click but doesn't redirect. I tried importing "router" and other troubleshooting steps but it's not working for me. Here is my html, and ts file.
html
<!--Theme Google Card - Full Image Cards-->
<ion-content padding-top>
<ion-grid no-padding>
<ion-row *ngIf="data != null">
<ion-col col-12 col-md-6 col-lg-6 *ngFor="let item of data.items;let i = index">
<ion-card text-left box-shadow margin-bottom>
<!--Card Image-->
<div card-image>
<img [src]="item.image" />
<div watch-now text-center (click)="onEvent('onItemClick', item, $event)">
<button ion-button button-icon icon-start>
<ion-icon icon-small [name]="item.icon"></ion-icon>
{{item.iconText}}
</button >
</div>
</div>
<!--Card descriptiom-->
<ion-card-content>
<ion-card-title text-center>
<!--Card Subtitle-->
<h1 card-title>{{item.title}}</h1>
<!-- Icon Rating Star -->
<ion-icon *ngFor="let star of item.ratingStar.iconsStars; let i = index" (click)="onStarClass(item.ratingStar.iconsStars, i, $event)">
<i icon-small *ngIf="star.isActive" class="icon {{star.iconActive}}"></i>
<i icon-small *ngIf="!star.isActive" class="icon {{star.iconInactive}}"></i>
</ion-icon>
<!-- Reviews Star -->
<span span-medium>{{item.reviews}}</span>
<!--Card Body Text-->
<p margin-top card-body-text>{{item.description}}</p>
</ion-card-title>
</ion-card-content>
</ion-card>
</ion-col>
</ion-row>
</ion-grid>
</ion-content>
TS
import { Component, Input, ViewChild } from '#angular/core';
import { IonicPage, Content } from 'ionic-angular';
#IonicPage()
#Component({
selector: 'google-card-layout-1',
templateUrl: 'google-card.html'
})
export class GoogleCardLayout1 {
#Input() data: any;
#Input() events: any;
#ViewChild(Content)
content: Content;
slider = {};
constructor() { }
slideHasChanged(slider, index): void {
this.slider[index] = slider;
if (2 == slider._activeIndex) {
if (this.data.items) {
this.data.items.splice(index, 1);
} else {
this.data.splice(index, 1);
}
}
}
onStarClass(items: any, index: number, e: any) {
if (e) {
e.stopPropagation();
}
for (var i = 0; i < items.length; i++) {
items[i].isActive = i <= index;
}
this.onEvent("onRates", index, e);
};
onClickEvent(index): void {
if (this.slider[index]) {
this.slider[index].slidePrev(300);
}
}
onEvent(event: string, item: any, e: any) {
if (e) {
e.stopPropagation();
}
if (this.events[event]) {
this.events[event](item);
}
}
}
Firstly you have to declare your route in your routing file in my case i have one newly created component so i update my route as follow
{
path: 'admin',
canActivate: [AuthGuard],
loadChildren: './pages/admin/admin.module#AdminModule'
},
After that there are two method to navigate,
1) <button [routerLink]="['/admin']" ion-button button-icon icon-start>
2) <button (click)="navigate()" ion-button button-icon icon-start>
and in your ts file add code
navigate() {
this.router.navgateURL(['/admin']);
}
Try:
<button [routerLink]="['/path']" ion-button button-icon icon-start>
Related
I have in this code a method openItem(anuncio, operacao)" that runs when I click on the object that will perform the action. In this case I don't understand why when running (click) = 'checkFavorite (advert) he also performs the action. Clicking the verifyFavorite action should only run it and not openItem. Could anyone help me? thanks !!!
<div class="ali-container">
<div class="ali-linha">
<div class="ali-capa-livro">
<button *ngIf="operacao !== vis" class="ali-capa-livro-btn" (click)="openItem(anuncio, operacao)">
<img src="{{anuncio.publicacao.imagem}}" width="40%" height="40%" />
</button>
<button *ngIf="operacao === vis" class="ali-capa-livro-btn">
<img src="{{anuncio.publicacao.imagem}}" width="40%" height="40%" />
</button>
</div>
<div class="ali-detalhes-livro">
<div class="ali-titulo-livro">{{anuncio.publicacao.titulo}}</div>
<div class="ali-autores-livro linha-unica-elipissis">{{anuncio.publicacao.autores}}</div>
<span class="ali-preco">{{anuncio.preco | currency:'R$':'code'}}</span>
<span class="ali-conservacao">({{anuncio.tipoConservacao}})</span>
<div class="ali-anunciante linha-unica-elipissis">por {{anuncio.usuario.nome}}</div>
<div class="ali-anunciante linha-unica-elipissis">{{anuncio.statusAnuncio}}</div>
<span>AnĂșncio: {{anuncio.tipoAnuncio.nome}} {{anuncio.tipoAnuncio.valor | currency:'R$':'code' }}</span>
</div>
<div *ngIf="operacao !== vis">
<button mode="ios" class="botao-excluir-anuncio" (click)="excluir(tipo, anuncio._id, favorito)" ion-button
round text-center item-end>
<ion-icon name="trash" item-end></ion-icon>
</button>
</div>
</div>
</div>
<div *ngIf="operacao === vis">
<div *ngIf="!anuncio.favorito">
<button mode="ios" class="botao-naoefavorito-anuncio" (click)='verificarFavorito(anuncio)' ion-button round
text-center item-end>
<ion-icon name="ios-heart-outline" item-end></ion-icon>
</button>
</div>
<div *ngIf="anuncio.favorito">
<button mode="ios" class="botao-favorito-anuncio" (click)='verificarFavorito(anuncio)' ion-button round
text-center item-end>
<ion-icon name="ios-heart" item-end></ion-icon>
</button>
</div>
<div *ngIf="apenasexcluir === 1">
<button mode="ios" class="botao-excluir-anuncio" (click)="excluir(tipo, anuncio._id, favorito)" ion-button round
text-center item-end>
<ion-icon name="trash" item-end></ion-icon>
</button>
</div>
</div>
import { Component, Input, Output, EventEmitter } from '#angular/core';
import { Anuncio } from '../../models/anuncio';
import { AppBasePage } from '../../pages/app-base-page/app-base-page';
import { AnuncioDetalhePage } from '../../pages/anuncio-detalhe/anuncio-detalhe';
import { NavController, NavParams } from 'ionic-angular';
import { AppGlobal } from '../../app/app.global';
import { AppRestService } from '../../services/app-rest.service';
import { RestNovoFavorito } from '../../services/app-rest.service';
#Component({
selector: 'anuncio-list-item',
templateUrl: 'anuncio-list-item.html'
})
export class AnuncioListItemComponent extends AppBasePage {
#Input('anuncio') anuncio: Anuncio;
#Input('tipo') tipo: any;
#Input('favorito') favorito: any;
#Input('cesta') cesta: any;
#Input('operacao') operacao: any;
#Input('apenasexcluir') apenasexcluir: any;
#Output() onExcluir: EventEmitter<any> = new EventEmitter();
#Output() onDetail: EventEmitter<any> = new EventEmitter();
constructor(private rest: AppRestService, private appGlobal: AppGlobal, public navCtrl: NavController, public navParams: NavParams) {
super();
}
openItem(anuncio, operacao, apenasexcluir) {
// quando origem cesta, chama com o parametro para atualizar a cesta de acordo com o anuncio alterado
if (this.cesta) this.navCtrl.push(AnuncioDetalhePage, { anuncio: anuncio, operacao: operacao, apenasexcluir: apenasexcluir, cesta: this.cesta });
else this.navCtrl.push(AnuncioDetalhePage, { anuncio: anuncio, operacao: operacao, apenasexcluir: apenasexcluir});
}
excluir(tipo, id, favorito) {
if (tipo == 1) {
this.onExcluir.emit(favorito);
} else
this.onExcluir.emit(id);
}
verificarFavorito(id) {
if (id.favorito) {
this.excluirFavorito(id.favorito._id)
} else {
this.incluirFavorito(id._id)
}
}
async excluirFavorito(id) {
await this.rest.excluirAnuncioFavorito(id);
}
async incluirFavorito(id) {
let restNovoFavorito = new RestNovoFavorito();
restNovoFavorito.anuncio = id;
await this.rest.incluirFavorito(restNovoFavorito);
}
}
This is my html code
<ion-searchbar [(ngModel)]="data" placeholder="Airlines" (ionInput)="getAirlines($event)">
</ion-searchbar>
<ion-list *ngIf="data">
<ion-item *ngFor="let item of airlines" (click)="airlinesClicked($event, item)">
<button ion-button item-start clear style="margin-right:2%; width:10%;height:10%" no-padding>
<img no-padding src="{{item.logo}}">
</button>
{{item.name}}
</ion-item>
</ion-list>
Iam trying to get searched result as list by filtering by each letters. While i am searching my list pushing my below contents down in my page. So i like to get my item as popover. Can anyone help me to get my result......
Thanks in advance
I'm not pretty sure but maybe when the data is ready you can create a popover controller and the resize the page.
import { PopoverController } from 'ionic-angular';
#Component({})
class yourClassName {
constructor(public PopOverCtrl: PopoverController) {}
presentPopover(event) {
let popover = this.popoverCtrl.create(ListPage);
popover.present({
ev: event
});
}
}
more details on Ionic website
You can use bootstrap for the following class tags
and create a custom list popover on ion-searchbar
<ion-row>
<ion-searchbar
(ionChange)="getAirlines($event)"
[(ngModel)]="data" placeholder="Airlines"
></ion-searchbar>
</ion-row>
<ion-row>
<ul
class="list-group position-absolute px-2 search-list w-100 rounded-2 shadow-sm"
*ngIf="data">
<li
*ngFor="let item of airlines"
class="list-group-item"
(click)="airlinesClicked($event,item)">
{{item.name}}
</li>
</ul>
</ion-row>
-----css
.search-list{
z-index: 9;
max-height: 150px;
overflow-y: auto;
}
I am new to Ionic and I am struck by this issue.
My issue is if I select any menu from {{menu.menuName}} then it will slide to respective tab but this will happen only if I am in app/home other than this URL above condition will not work.Please help.
menu.html
<ion-side-menu side="left">
<ion-header-bar class="bar-balanced">
<h1 class="title">App</h1>
</ion-header-bar>
<ion-content>
<ion-list>
<ion-item menu-close href="#/app/home">
<i class="icon ion-home"></i> Home
</ion-item>
<ion-item menu-close ng-click="createDirectory()">
<i class="icon ion-android-create"></i> Create Name
</ion-item>
<ion-list ng-controller="HomeCtrl">
<div ng-repeat="menu in mainMenu ">
<ion-item class="item-stable"
ng-click="toggleGroup(menu)"
ng-class="{active: isGroupShown(menu)}" style="color:#11c1f3;">
{{menu.menuName}} <i class="icon" style="position: absolute;
right: 8%;" ng-class="isGroupShown(menu) ? 'ion-minus' : 'ion-plus'"></i>
</ion-item>
<ion-item class="item-accordion"
ng-repeat="($index, directories) in directoryList"
ng-class="{'': $index === current}"
ng-click="changeSlide($index,directoryList)"
ng-show="isGroupShown(menu)" style="color:#E47006;" >
{{directories.directoryName}}
</ion-item>
</div>
</ion-list>
</ion-list>
</ion-content>
Controller.js
$scope.changeSlide = function (index,directoryName)
{
console.log('Slide changed to ' + index);
var data= directoryName[index]
if(data !=null){
var directoryId =data.directoryId;
data.dirId = directoryId;
getImages();
function getImages() {
userService.getImages(data).then(function(response) {
$scope.imageData = response;
$scope.current = index;
$ionicSlideBoxDelegate.slide(index);
},function(error) {
})
}
}
$scope.ready.push(index + ': ' + true);
};
app.js
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('app.home',{
url:'/home',
cache:false,
views:{
'menuContent':{
templateUrl:'templates/home.html',
controller:'HomeCtrl'
}
}
})
.state('app.profileUpdate',{
url:'/profileUpdate',
cache:false,
views:{
'menuContent':{
templateUrl:'templates/profileUpdate.html',
controller:'ProfileUpdate'
}
}
});
$urlRouterProvider.otherwise('/app/home');
});
home.html
<ion-view view-title="Home" hide-back-button="true" style="margin-top: 45px;">
<ion-content scroll="false" style="top:0px;" >
<ion-slide-box slide-tabs-scrollable="true" show-pager="false" on-slide-changed="changeSlide(index,directoryList)" bounce="false" ion-slide-tabs>
<ion-slide ng-repeat="(key, catg) in directoryList" ion-slide-tab-label="{{catg.directoryName}}" style="background-color:white;">
<br><br>
<div class="row gallery">
<div class="col col-33" ng-repeat="element in imageData" ng-click="showImages($index)">
<img ng-src="data:image/jpeg;base64,{{element.imagePath}}" width="100%" />
</div>
</div>
<center ng-if="!ready[key]">
<br>
<ion-spinner></ion-spinner>
</center>
<br></br><br></br><br></br>
</ion-slide>
</ion-slide-box>
</ion-content>
</ion-view>
I have changed methods as mentioned below, I am adding this if in case anyone needs,
fetchDirectories();
function fetchDirectories(){
userService.fetchDirectories()
.then(function(response) {
$scope.directoryList = response;
$scope.lastView = $ionicHistory.backView() ;
if($scope.lastView !=null){
if($scope.lastView.stateName != 'app.home'){
var indexNumber = sessionStorage.getItem("indexNumber");
$scope.changeSlide(indexNumber,$scope.directoryList);
}
}else{
$scope.changeSlide(0,$scope.directoryList);
}
window.dispatchEvent(new Event('resize'));
},
function(errResponse){
}
);
};
$scope.changeSlide
$scope.changeSlide = function (index,directoryName)
{
console.log('Slide changed to ' + index);
if($location.path() == '/app/home'){
console.log($location.path());
var data= directoryName[index]
if(data !=null){
var directoryId =data.directoryId;
data.dirId = directoryId;
getImages();
function getImages() {
userService.getImages(data).then(function(response) {
$scope.imageData = response;
$scope.current = index;
$ionicSlideBoxDelegate.slide(index);
},function(error) {
})
}
}
$scope.ready.push(index + ': ' + true);
}
else if($location.path() != '/app/home'){
sessionStorage.setItem("indexNumber",index);
$state.go('app.home');
}
}
I'm using Bluetooth serial in my Ionic2 app and I want to connect to the device.
Got this now in the .ts file but doesn't works. I can enable bluetooth but cant connect.
import { Component } from '#angular/core';
import { BluetoothSerial } from 'ionic-native';
import { NavController } from 'ionic-angular';
#Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
public stat_on:any;
public stat_con:any;
public macAddress:"98:D3:31:90:77:36";
constructor(public navCtrl: NavController) {
}
turnON(){
BluetoothSerial.enable().then((status)=> {
this.stat_on=status;
});
}
Connect(){
BluetoothSerial.isEnabled().then((data)=> {
BluetoothSerial.connect("98:D3:31:90:77:36").then((stat_con)=>{
this.stat_con=stat_con;
});
});
}
}
Here is my HTML file
<ion-header>
<ion-navbar>
<ion-title>Home</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<ion-fab right bottom>
<button ion-fab color="light"><ion-icon name="arrow-dropleft"></ion-icon></button>
</ion-fab>
<ion-card-content>
<button ion-button (click)="turnON()">Turn ON Bluetooth</button>
<button ion-button (click)="Connect()">Connect</button>
<p>BT: {{ stat_on }}</p>
<p>Status: {{ stat_connect }}</p>
</ion-card-content>
</ion-content>
Thanks before :)
I doing thank you page in my project. in success call it will display ORDER DETAILS and Delivery Details & Failure call it will display only ORDER DETAILS..
Success call is working fine but failure call not displaying order details...
below is my html code..
<!--
Generated template for the ThankYouPage page.
See http://ionicframework.com/docs/v2/components/#navigation for more info on
Ionic pages and navigation.
-->
<ion-header>
<ion-navbar>
<ion-title>Order Summary</ion-title>
<ion-buttons end>
<button ion-button icon-only>
<ion-icon name="share"></ion-icon>
</button>
</ion-buttons>
</ion-navbar>
</ion-header>
<ion-content>
<div *ngIf="orderSuccess">
<ion-item no-lines>
<ion-row>
<ion-icon ios="ios-checkmark-circle" md="md-checkmark-circle" class="success"></ion-icon>
</ion-row>
<ion-row class="text-center">
<p>Thank you. Your order has been</p>
</ion-row>
<ion-row class="text-center"><p>Successfully Placed.</p></ion-row>
</ion-item>
<hr>
</div>
<div *ngIf="orderFailure">
<ion-item>
<ion-row>
<ion-icon ios="ios-close-circle" md="md-close-circle" class="failure"></ion-icon>
</ion-row>
<ion-row class="text-center">
<p>Sorry! Failed to place your order.</p>
</ion-row>
<ion-card>
<ion-card-content>
Your Order could not be completed because of the-"System Generated Issue"
</ion-card-content>
</ion-card>
</ion-item>
</div>
<ion-item *ngFor=" let item of orderDetailsArray">
<div class="div"> Order Details </div>
<ion-row *ngIf="orderSuccess">
<ion-col class="down">Order Date</ion-col><br>
<ion-col class="down">{{item.date_added | date:'MMM-dd-yyyy'}}</ion-col>
</ion-row>
<ion-row *ngIf="orderSuccess">
<ion-col>Order number</ion-col><br>
<ion-col>{{item.order_id}}</ion-col>
</ion-row>
<hr>
<ion-row class="row">
<ion-col class="lightbold">Order Total</ion-col><br>
<ion-col class="bold">$ {{item.total}}</ion-col>
</ion-row>
<ion-row class="pay">
<ion-col>Payment method:</ion-col><br>
<ion-col class="color">{{item.payment_method}}</ion-col>
</ion-row>
</ion-item>
<div *ngIf="orderSuccess">
<ion-item *ngFor=" let item of orderDetailsArray">
<div class="div"> Delivery Details </div>
<div class="font">
<div>{{item.shipping_firstname}} {{item.shipping_lastname}}</div>
<div>{{item.shipping_address_1}} , {{item.shipping_address_2}}</div>
<div>{{item.shipping_city}}, {{item.shipping_postcode}}</div>
<div>{{item.shipping_zone}}</div>
<div class="phone">
<ion-icon ios="ios-call" md="md-call" item-left></ion-icon>
<span>{{item.telephone}}</span>
</div>
<div class="mail">
<ion-icon ios="ios-mail" md="md-mail" item-left></ion-icon>
<span>{{item.email}}</span>
</div>
</div>
</ion-item>
</div>
</ion-content>
<ion-footer>
<ion-toolbar color="primary">
<div *ngIf="orderSuccess">
<ion-row class="center" (click)="submit();"> GO BACK HOME </ion-row>
</div>
<div *ngIf="orderFailure">
<ion-row class="center" (click)="submit();"> GO BACK HOME </ion-row>
</div>
</ion-toolbar>
</ion-footer>
below is my ts file...
import { Component } from '#angular/core';
import { NavController } from 'ionic-angular';
import { Rest } from '../../providers/network/rest';
import { Logger } from '../../providers/logger/logger';
/*
Generated class for the ThankYou page.
See http://ionicframework.com/docs/v2/components/#navigation for more info on
Ionic pages and navigation.
*/
#Component({
selector: 'page-thank-you',
templateUrl: 'thank-you.html'
})
export class ThankYouPage {
orderDetailsArray = [];
public orderSuccess:boolean =false;
public orderFailure:boolean =false;
constructor(public navCtrl: NavController,
public rest: Rest,
public logger: Logger) {}
ionViewDidLoad() {
this.rest.get('/getOrder&order_id=0')
.subscribe((result) => {
console.log("checking getOrder"+JSON.stringify(result));
if(result.status == '1'){
console.log("success of getOrder");
this.orderDetailsArray=result.order;
this.orderSuccess=true;
}
else{
console.log("error of getOrder");
this.orderFailure = true;
}
})
}
submit(){
//this.navCtrl.setRoot(HomePage,{});
}
notSubmit(){
//this.navCtrl.push(PaymentPage,{});
}
}
Success call is working fine but failure call is not displaying order details...
It's because you are only setting the orderDetailsArray if your result.status is 1!
You should do it like this:
ionViewDidLoad() {
this.rest.get('/getOrder&order_id=0')
.subscribe((result) => {
console.log("checking getOrder"+JSON.stringify(result));
this.orderDetailsArray=result.order; // <-- place it here !
if(result.status == '1') {
console.log("success of getOrder");
this.orderSuccess=true;
}
else {
console.log("error of getOrder");
this.orderFailure = true;
}
});
}
You can also use this to convert result.status into Integer.Try this because status should always come in integer type and you are using string.I hope it will help you.
if(((result.status)*1) == 1) {...}