Slider content or view not changing based on menu click - html

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');
}
}

Related

Ionic 3 tabbar getting disappear when routing from sidebar

In My ionic 3 app the tab bar is getting disappear when navigating from side bar. All other pages are working fine. Only when routing from side bar, tab is getting disappear.
Here is my app.html
<ion-menu [content]="content" type="overlay">
<ion-content class="menubar">
<ion-list class="mainmenu">
<div class="profile">
<ion-row>
<ion-col col-4><img src="./assets/imgs/wgs-logo.png" alt=""></ion-col>
<ion-col col-8 class="j-c-center" (click)="openLandingPage()">
<ion-icon slot="start" class="landing-page-icon" name="custom-landing-page"></ion-icon>
</ion-col>
</ion-row>
</div>
<ion-item no-lines class="menuitem" *ngFor="let cate of categoryFullData; let i = index;">
<button ion-button clear menuToggle (click)="opencategory(cate.id, cate.categry)">
<img src="{{baseUrlImage}}{{cate.cateimg}}">
<p>{{cate.categry}}</p>
</button>
<ion-icon slot="end" name="ios-arrow-down" class="icon-down-arrow" (click)="menuItemHandler(i)"></ion-icon>
<ion-item-group submenu [class.visible]="showSubmenu[i]">
<ion-item no-lines class="menuitem" *ngFor="let subcate of cate.subcategories; let i = index;">
<button ion-button clear (click)="opencategory(subcate.id, subcate.categry)" menuToggle>
<img src="{{baseUrlImage}}{{subcate.cateimg}}">
<p>{{subcate.categry}}</p>
</button>
</ion-item>
</ion-item-group>
</ion-item>
<ion-item no-lines class="menuitem">
<button ion-button clear menuToggle (click)="openLandingPage()">
Sell
</button>
</ion-item>
<ion-item no-lines class="menuitem">
<button ion-button clear menuToggle (click)="openAboutUs()">
<p>About Us</p>
</button>
</ion-item>
<ion-item no-lines class="menuitem">
<button ion-button clear menuToggle (click)="openTermsAndConditions()">
<p>Terms & Conditions</p>
</button>
</ion-item>
<ion-item no-lines class="menuitem">
<button ion-button clear menuToggle (click)="openPrivacyPolicy()">
<p>Privacy Policy</p>
</button>
</ion-item>
</ion-list>
</ion-content>
</ion-menu>
<ion-nav [root]="rootPage" #content swipeBackEnabled="false"></ion-nav>
Here is my app.component.ts
import { Component, ViewChild } from '#angular/core';
import { Nav, Platform, App, LoadingController, AlertController, ToastController } from 'ionic-angular';
import { StatusBar } from '#ionic-native/status-bar';
import { SplashScreen } from '#ionic-native/splash-screen';
import { NotificationsPage } from '../pages/notifications/notifications';
import { OrderHistoryPage } from '../pages/order-history/order-history';
import { ContactPage } from '../pages/contact/contact';
import { FeedbackPage } from '../pages/feedback/feedback';
import { HomePage } from '../pages/home/home';
import { OffersPage } from '../pages/offers/offers';
import { TermsPage } from '../pages/terms/terms';
import { HkApiproviderProvider } from '../providers/hk-apiprovider/hk-apiprovider';
import { CategoryPage } from '../pages/category/category';
import { LanguageServiceProvider } from '../providers/language-service/language-service';
import { TranslateService } from '#ngx-translate/core';
import { TabsPage } from '../pages/tabs/tabs';
import { ProductsPage } from '../pages/products/products';
import { LandingPage } from '../pages/landing-page/landing-page';
import { PrivacyPage } from '../pages/privacy/privacy';
#Component({
templateUrl: 'app.html'
})
export class MyApp {
#ViewChild(Nav) nav: Nav;
validEmail:any;
rootPage: any = TabsPage;
showSubmenu = [];
resposeData: any;
categoryFullData:any;
pages: Array<{title: string, component: any}>;
apptoken = {"token":""};
postData={
"user_id":"",
"token":"",
}
baseUrlImage: any;
itemsuperqty: number;
userDetails: any;
constructor(public platform: Platform, public auth:HkApiproviderProvider,public app:App, public toastCtrl: ToastController, public loadingCtrl:LoadingController, public alertCtrl:AlertController, public statusBar: StatusBar, public splashScreen: SplashScreen,public langserv : LanguageServiceProvider, translate: TranslateService) {
this.initializeApp();
this.apptoken.token = HkApiproviderProvider.gettoken();
localStorage.setItem('appconfig', JSON.stringify(this.apptoken));
langserv.getdefaultlang();
translate.setDefaultLang(langserv.defaultlang);
this.langserv.changelang('en');
this.itemsuperqty = 1;
this.baseUrlImage = auth.getimage();
if(localStorage.getItem('userData')){
const data = JSON.parse(localStorage.getItem('userData'));
this.userDetails = data.userData;
}
this.postData.token = HkApiproviderProvider.gettoken();
this.getcategorydata();
}
/* menuItemHandler(): void {
this.showSubmenu = !this.showSubmenu;
} */
initializeApp() {
this.platform.ready().then(() => {
this.statusBar.backgroundColorByHexString('#307722');
this.splashScreen.hide();
});
}
onclickHome(){
this.nav.setRoot(HomePage , { tabIndex: 0 });
}
onclickcategory(){
this.nav.push(CategoryPage , { tabIndex: 0 });
}
onclickMyOrder(){
this.nav.push(OrderHistoryPage , { tabIndex: 1 });
}
openContact(){
this.nav.push(ContactPage , { tabIndex: 0 });
}
onclickNoti(){
this.nav.push(NotificationsPage , { tabIndex: 0 });
}
openfeedback(){
this.nav.push(FeedbackPage , { tabIndex: 0 });
}
openoffers(){
this.nav.push(OffersPage , { tabIndex: 0 });
}
openterms(){
this.nav.push(TermsPage , { tabIndex: 0 });
}
openprivacy(){
this.nav.push(TermsPage , { tabIndex: 0 });
}
openLandingPage(){
this.nav.push(LandingPage);
}
checkLogin(){
if(localStorage.getItem('userData')){
return true;
}else{
return false;
}
}
menuItemHandler(index): void {
if(this.showSubmenu[index] && this.showSubmenu[index] == false) {
this.showSubmenu[index] = true;
} else if (this.showSubmenu[index] && this.showSubmenu[index] == true) {
this.showSubmenu[index] = false;
} else {
this.showSubmenu[index] = true;
}
}
public getcategorydata()
{
let zest = this.loadingCtrl.create({
content: "Getting Data..",
duration:20000,
spinner:'crescent'
});
zest.present();
this.auth.postData(this.postData, "getcategory").then((result) => {
this.resposeData = result;
this.categoryFullData = this.resposeData.Data;
//console.log(result);
zest.dismiss();
}, (err) => {
zest.dismiss();
});
}
opencategory(category, cname){
this.nav.push(ProductsPage,{
category : category,
cname : cname,
tabIndex: 1
});
}
openAboutUs() {
this.nav.push(ContactPage);
}
openTermsAndConditions() {
this.nav.push(TermsPage);
}
openPrivacyPolicy() {
this.nav.push(PrivacyPage);
}
}
This is my tabs.html page
<ion-tabs>
<ion-tab [root]="tab6Root" class="tab-bar" tabIcon="custom-landing-page">
</ion-tab>
<ion-tab [root]="tab1Root" class="tab-bar" tabIcon="ios-home-outline">
</ion-tab>
<ion-tab [root]="tab2Root" class="tab-bar" tabIcon="ios-person-outline">
</ion-tab>
<ion-tab [root]="tab3Root" class="tab-bar" tabIcon="icon-cart-white" [tabBadge]="cartCounterManager()">
</ion-tab>
<ion-tab [root]="tab4Root" class="tab-bar" tabIcon="ios-heart-outline" [tabBadge]="wishListCounterManager()">
</ion-tab>
<ion-tab [root]="tab5Root" class="tab-bar" tabIcon="ios-search-outline">
</ion-tab>
</ion-tabs>
tabs.component.ts
import { Component } from '#angular/core';
import { ProductSearchPage } from '../product-search/product-search';
import { ProfilePage } from '../profile/profile';
import { HomePage } from '../home/home';
import { CartPage } from '../cart/cart';
import { WishListPage } from '../wishlist/wishlist';
import { NavController, NavParams } from 'ionic-angular';
import { LoginPage } from '../login/login';
import { ProductsPage } from '../products/products';
import { LandingPage } from '../landing-page/landing-page';
#Component({
templateUrl: 'tabs.html'
})
export class TabsPage {
tab1Root = HomePage;
tab2Root = ProfilePage;
tab3Root = CartPage;
tab4Root = WishListPage;
tab5Root = ProductSearchPage;
tab6Root = LandingPage;
selectedIndex: Number;
constructor(
public navCtrl: NavController,
public navParams: NavParams,
){
}
ionViewDidLoad() {
this.selectedIndex = this.navParams.get('tabIndex') || 0;
console.log(this.selectedIndex)
}
cartCounterManager(){
return HomePage.cartData.length
}
wishListCounterManager(){
return HomePage.wishListData.length
}
}
I tried every method available but none works. Please help. Every small comments will be appreciated.

Two different actions being performed

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);
}
}

Redirect to another page using angular 6

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>

how to display details using ng for in ionic 2

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) {...}

Ionic Side Menu Not Showing Content

I am working on my first ionic/angularjs app and have hit a snag. I can get the page to load like I want with a tabbed navigation and side menu but the content in the side menu won't show for some reason. It is in the page, I can see it in view source but it will not show no matter what manipulation I try to the styling. Being new to this I am at a loss for what to do now. Below is the code.
Index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>
<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
<link href="css/ionic.app.css" rel="stylesheet">
-->
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>
<script src="js/user-object.js"></script>
<script src="js/news-feed-object.js"></script>
<!-- your app's js -->
<script src="js/app.js"></script>
<!-- your controllers js -->
<script src="js/controllers.js"></script>
<script src="js/services.js"></script>
</head>
<body ng-app="wgn">
<ion-nav-bar class="bar-energized nav-title-slide-ios7 ">
<div ng-controller="MenuCtrl">
<ion-side-menus>
<fade-bar></fade-bar>
<ion-pane ion-side-menu-content>
<header class="bar bar-header bar-energized nav-title-slide-ios7">
<button class="button button-icon" ng-click="openLeft()"><i class="icon ion-navicon"></i>
</button>
<h1 class="title">Test App</h1>
</header>
<ion-content has-header="true" padding="true">
<!-- Center content -->
</ion-content>
</ion-pane>
<ion-side-menu side="left">
<header class="bar bar-header bar-dark" fade-header>
<h1>Left</h1>
</header>
<ion-content has-header="true">
<div>Content</div>
<div>Content</div>
<div>Content</div>
<div>Content</div>
<div>Content</div>
<div>Content</div>
<div>Content</div>
<div>Content</div>
</ion-content>
</ion-side-menu>
</ion-side-menus>
</div>
<ion-nav-back-button class="button-icon ion-arrow-left-c ">
</ion-nav-back-button>
</ion-nav-bar>
<ion-nav-view animation="slide-left-t">
</ion-nav-view>
</body>
</html>
tabs.html
<ion-tabs class="tabs-icon-top tabs-energized">
<ion-tab title="Home" icon="ion-home" href="#/tab/events">
<ion-nav-view name="home-tab"></ion-nav-view>
</ion-tab>
<ion-tab title="About" icon="ion-ios7-information" href="#/tab/about">
<ion-nav-view name="about-tab"></ion-nav-view>
</ion-tab>
<ion-tab title="Sign-Out" icon="ion-log-out" href="#/sign-in">
</ion-tab>
</ion-tabs>
app.js
// Ionic Starter App
// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
angular.module('wgn', ['ionic', 'wgn.controllers', 'wgn.services'])
.run(function ($ionicPlatform) {
$ionicPlatform.ready(function () {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if (window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if (window.StatusBar) {
StatusBar.styleDefault();
}
});
})
.config(function ($stateProvider, $urlRouterProvider) {
$stateProvider.state('signin', {
url: "/sign-in",
templateUrl: "templates/sign-in.html",
controller: 'SignInCtrl'
}).state('forgotpassword', {
url: "/forgot-password",
templateUrl: "templates/forgot-password.html"
}).state('slidemenu', {
url: "/slide-menu.html",
abstract: true,
templateUrl: 'templates/slide-menu.html'
}).state('tabs', {
url: "/tab",
abstract: true,
templateUrl: "templates/tabs.html"
}).state('tabs.home', {
url: "/home",
views: {
'home-tab': {
templateUrl: "templates/home.html",
controller: 'HomeTabCtrl'
}
}
}).state('tabs.eventdetails', {
url: "/eventdetails/:eventid",
views: {
'home-tab': {
templateUrl: "templates/event-details.html",
controller: 'EventDetailsCtrl'
}
}
}).state('tabs.addevents', {
url: "/addevents",
views: {
'home-tab': {
templateUrl: "templates/addevents.html"
}
}
}).state('tabs.about', {
url: "/about",
views: {
'about-tab': {
templateUrl: "templates/about.html"
}
}
}).state('tabs.navstack', {
url: "/navstack",
views: {
'about-tab': {
templateUrl: "templates/nav-stack.html"
}
}
}).state('tabs.contact', {
url: "/contact",
views: {
'contact-tab': {
templateUrl: "templates/contact.html"
}
}
});
$urlRouterProvider.otherwise("/sign-in");
});
controller.js
angular.module('wgn.controllers', [])
.controller('SignInCtrl', function ($scope, $state) {
$scope.signIn = function (user) {
console.log('Sign-In', user);
$state.go('tabs.home');
};
}).controller('HomeTabCtrl', function ($scope, WGNEvents, $ionicModal) {
console.log('HomeTabCtrl');
$scope.wgnEvents = WGNEvents.all();
$scope.user = userObject;
$scope.newsFeedList = newsFeedObjectList;
//Add Event
$ionicModal.fromTemplateUrl('templates/addevents.html', {
scope: $scope,
animation: 'slide-in-up'
}).then(function (modal) {
$scope.modal = modal;
});
$scope.addEvent = function () {
$scope.modal.show();
console.log('show modal');
};
$scope.closeModal = function () {
$scope.modal.hide();
};
//Cleanup the modal when we're done with it!
$scope.$on('$destroy', function () {
$scope.modal.remove();
});
// Execute action on hide modal
$scope.$on('modal.hidden', function () {
// Execute action
});
// Execute action on remove modal
$scope.$on('modal.removed', function () {
// Execute action
});
}).controller('EventDetailsCtrl', function ($scope, WGNEvents, $stateParams) {
console.log('EventDetailsCtrl');
var eventID = $stateParams.eventid;
console.log('event-id: ' + eventID);
$scope.wgnEvents = WGNEvents.get(eventID);
console.log($scope.wgnEvents);
}).controller('HomePageCtrl', function ($scope, WGNEvents, $ionicModal) {
console.log('HomePageCtrl');
$scope.getClass = function (score, par) {
return {
'below-par': (par - score) > 0,
'above-par': (par - score) < 0,
'text-dark': (par - score) == 0
};
}
$scope.getOverUnder = function (score, par) {
var total = score - par;
if (total === 0) {
total = 'E';
} else if (total > 0) {
total = '+' + total;
}
return total;
}
}).controller('MenuCtrl', function($scope) {
// Our controller
})
// The fadeBar directive
.directive('fadeBar', function($timeout) {
return {
restrict: 'E',
template: '<div class="fade-bar"></div>',
replace: true,
link: function($scope, $element, $attr) {
// Run in the next scope digest
$timeout(function() {
// Watch for changes to the openRatio which is a value between 0 and 1 that says how "open" the side menu is
$scope.$watch('sideMenuController.getOpenRatio()', function(ratio) {
// Set the transparency of the fade bar
$element[0].style.opacity = Math.abs(ratio);
});
});
}
}
});
Side Menus should not be in your ionNavBar container. I've got an example here showing how to use SideMenu, Tabs, and Navigation elements together. You're close, its just some things don't really work well when they are placed in the wrong place.
http://codepen.io/gnomeontherun/pen/EfKgJ
Markup
<ion-side-menus>
<ion-pane ion-side-menu-content>
<ion-nav-bar class="bar-positive nav-title-slide-ios7">
<ion-nav-back-button class="button-icon"><span class="icon ion-ios7-arrow-left"></span></ion-nav-back-button>
</ion-nav-bar>
<ion-nav-view></ion-nav-view>
</ion-pane>
<ion-side-menu side="left">
<ion-header-bar class="bar bar-header bar-dark"></ion-header-bar>
<ion-content has-header="true">
<ion-list>
<ion-item href="#/" ng-click="sideMenuController.toggleLeft()">Home</ion-item>
</ion-list>
</ion-content>
</ion-side-menu>
<ion-side-menu side="right" >
<ion-header-bar class="bar bar-header bar-dark" title="Search"></ion-header-bar>
<ion-content has-header="true">
</ion-content>
</ion-side-menu>
</ion-side-menus>
<script id="home.html" type="text/ng-template">
<ion-view title="Home">
<ion-nav-buttons side="right">
<button class="button button-icon button-clear ion-plus" ng-click="openModal()"></button>
</ion-nav-buttons>
<ion-nav-buttons side="left">
<button class="button button-icon button-clear ion-navicon" ng-click="openMenu()"></button>
</ion-nav-buttons>
<ion-tabs class="tabs-positive">
<ion-tab title="Stooges">
<h4>The Stooges</h4>
<ion-list>
<ion-item ng-repeat="stooge in stooges" href="#/{{stooge.name}}">{{stooge.name}}</ion-item>
</ion-list>
</ion-tab>
<ion-tab title="Tab 2">
<h2>Just another tab, for another reason</h2>
</ion-tab>
</ion-tabs>
</ion-view>
</script>
<script id="modal.html" type="text/ng-template">
<div class="modal">
<ion-header-bar class="bar bar-header bar-positive">
<h1 class="title">New Stooge</h1>
<button class="button button-clear button-primary" ng-click="modal.hide()">Cancel</button>
</ion-header-bar>
<ion-content>
<div class="padding">
<div class="list">
<label class="item item-input">
<span class="input-label">Name</span>
<input ng-model="form.name" type="text" name="name" />
</label>
<button class="button button-full button-positive" ng-click="addStooge()">Create</button>
</div>
</div>
</ion-content>
</div>
</script>
<script id="item.html" type="text/ng-template">
<ion-view title="{{item}}">
<ion-content>
<h1>{{item}}</h1>
</ion-content>
</ion-view>
</script>
JavaScript
angular.module('ionicApp', ['ionic'])
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('home', {
url: '/',
controller: 'HomeCtrl',
templateUrl: 'home.html'
})
.state('item', {
url: '/:item',
controller: 'ItemCtrl',
templateUrl: 'item.html'
});
$urlRouterProvider.otherwise('/');
})
.controller('HomeCtrl', function($scope, $ionicSideMenuDelegate, $ionicModal) {
$scope.stooges = [{name: 'Moe'}, {name: 'Larry'}, {name: 'Curly'}];
$ionicModal.fromTemplateUrl('modal.html', {
animation: 'slide-in-up',
scope: $scope
}).then(function (modal) {
$scope.modal = modal;
});
$scope.openMenu = function () {
$ionicSideMenuDelegate.toggleLeft();
}
$scope.openModal = function () {
$scope.modal.show();
}
$scope.form = {};
$scope.addStooge = function () {
console.log($scope);
$scope.stooges.push({name: $scope.form.name});
$scope.modal.hide();
};
$scope.$on('$destroy', function() {
$scope.modal.remove();
});
})
.controller('ItemCtrl', function ($scope, $stateParams) {
$scope.item = $stateParams.item;
});