Ionic 2 side menu always visible - css

I have a requirement to always display side menu and hide menu icon in the title bar when my app is loaded in tablet devices. I tried a lot but no success. Can anyone though some light here?

Starting from Ionic version 2.2.0 there is an out of the box solution for this, called split pane:
<ion-split-pane>
<ion-menu [content]="myNav"></ion-menu>
<ion-nav #myNav main><ion-nav>
</ion-split-pane>
More information here

I think you are looking for the showWhen and hideWhen properties. Documentation here. Indeed, there is a tablet platform. But you will be confronted with this : when a user clicks outside a menu, he closes it.
As I explained here, what I would do to have a such behavior is to use a component wrapper inside the menu content and use this same wrapper with a showWhen property on tablet in the <ion-content>.
EDIT : Adding code to illustrate the solution I proposed.
Menu always visible on some platforms behavior like example
Test environment :
Cordova CLI: 6.2.0
Ionic Framework Version: 2.0.0-rc.3
Ionic CLI Version: 2.1.8
Ionic App Lib Version: 2.1.4
Ionic App Scripts Version: 0.0.45
ios-deploy version: Not installed
ios-sim version: Not installed
OS: Linux 3.19
Node Version: v6.9.1
Xcode version: Not installed
App
./src/app/app.component.html :
<ion-menu
[content]="root"
>
<ion-header>
<ion-toolbar>
<ion-title>
Menu
</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<sitemap-component
hideWhen="tablet, phablet"
>
</sitemap-component>
</ion-content>
</ion-menu>
<ion-nav
#root
[root]="rootPage"
>
</ion-nav>
./src/app/app.component.ts :
import { Component } from '#angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar, Splashscreen } from 'ionic-native';
import { HomePage } from '../pages/home/home';
#Component({
templateUrl: "app.component.html"
})
export class MyApp {
rootPage = HomePage;
constructor(platform: Platform) {
platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
StatusBar.styleDefault();
Splashscreen.hide();
});
}
}
./src/app/app.module.ts :
import { NgModule, ErrorHandler } from '#angular/core';
import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import { SitemapComponent } from '../components/sitemap/sitemap.component';
import { ContentComponent } from '../components/content/content.component';
#NgModule({
declarations: [
MyApp,
HomePage,
SitemapComponent,
ContentComponent
],
imports: [
IonicModule.forRoot(MyApp)
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage,
SitemapComponent,
ContentComponent
],
providers: [{provide: ErrorHandler, useClass: IonicErrorHandler}]
})
export class AppModule {}
Main content (platform independent)
./src/components/content/content.component.html :
<p>
Here is the main content.
</p>
<button
ion-button
menuToggle
>
Menu
</button>
./src/components/content/content.component.scss :
content-component {
}
./src/components/content/content.component.ts :
import {Component} from '#angular/core'
#Component(
{
selector : 'content-component'
, templateUrl : 'content.component.html'
}
)
export class ContentComponent
{
constructor()
{
}
}
Sitemap (in menu or in main content part, according to the platform)
./src/components/sitemap/sitemap.component.html :
<p
hideWhen="tablet, phablet"
>
Here is the menu content on a platform that is neither a tablet nor a phablet.
</p>
<p
showWhen="tablet, phablet"
>
Here is the menu content on a platform that is a tablet or a phablet.
</p>
<ion-list
>
<ion-item
*ngFor="let item of item_array"
>
{{item}}
</ion-item>
</ion-list>
./src/components/sitemap/sitemap.component.scss :
sitemap-component {
}
./src/components/sitemap/sitemap.component.ts :
import {Component} from '#angular/core'
#Component(
{
selector : 'sitemap-component'
, templateUrl : 'sitemap.component.html'
}
)
export class SitemapComponent
{
item_array =
[
"foo"
, "bar"
]
constructor()
{
}
}
Home page
./src/pages/home/home.html :
<ion-header>
<ion-navbar>
<ion-title>
Ionic Blank
</ion-title>
</ion-navbar>
</ion-header>
<ion-content
padding
>
<div
showWhen="tablet, phablet"
>
<ion-row>
<ion-col
width-20
>
<sitemap-component>
</sitemap-component>
</ion-col>
<ion-col
width-80
>
<content-component>
</content-component>
</ion-col>
</ion-row>
</div>
<div
hideWhen="tablet, phablet"
>
<content-component>
</content-component>
</div>
</ion-content>
./src/pages/home/home.scss :
page-home {
}
./src/pages/home/home.ts :
import { Component } from '#angular/core';
#Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
constructor()
{
}
}
Hope this helps!

Related

How do I implement paging (JwPaginationModule) in my Ionic app?

I have a list with cars. Now I want to integrate paging because of the many records.
This is my ListViewPageModule in which I imported JwPagingationModule:
import { NgModule } from '#angular/core';
import { CommonModule } from '#angular/common';
import { FormsModule } from '#angular/forms';
import { JwPaginationModule } from 'jw-angular-pagination';
import { IonicModule } from '#ionic/angular';
import { ListViewPageRoutingModule } from './list-view-routing.module';
import { ListViewPage } from './list-view.page';
import { ComponentsModule } from '../components.module';
#NgModule({
imports: [
CommonModule,
FormsModule,
IonicModule,
ComponentsModule,
ListViewPageRoutingModule,
JwPaginationModule
],
declarations: [ListViewPage]
})
export class ListViewPageModule {}
My Component:
#Component({
selector: 'app-list-view',
templateUrl: './list-view.page.html',
styleUrls: ['./list-view.page.scss'],
})
export class ListViewPage implements OnInit {
structureGroups: StructureGroup[] = [];
lablesHeadlines = lablesHeadlines;
headlines = lablesHeadlines;
pageOfItems: Array<any>;
constructor(private listClientService: ListClientServiceService, private router: Router) { }
ngOnInit() {
this.listClientService.getAllCarGroupNamesWithId().subscribe(
(response) => {
this.carGroups = response;
return response;
});
}
openCarGroup(id: number) {
this.router.navigate(['/detail-view', { carGroupId: id }]);
}
onChangePage(pageOfItems: Array<any>) {
// update current page of items
this.pageOfItems = pageOfItems;
}
}
My HTML:
1 <ion-content>
2 <ion-list id="list">
3 <ion-item id="list-item" button *ngFor="let carGroup of carGroups"
4 (click)="openCarGroup(carGroup.id)">
5 <ion-label>{{carGroup.carGroupName}}</ion-label>
6 </ion-item>
7 </ion-list>
8 <div class="card-footer pb-0 pt-3">
9 <jw-pagination [carGroups]="carGroups" (changePage)="onChangePage($event)"></jw-pagination>
10 </div>
</ion-content>
My CSS
.card-footer{
width: 100%;
height: 10%;
position: absolute;
bottom: 10px;
}
I am unfortunately still very inexperienced when it comes to working with ionic and Angular. Currently I get the error:
NG0303: Can't bind to 'carGroups' since it isn't a known property of 'jw-pagination'.
This error comes from my HTML file line 9.
Question 1: How can I fix the error?
Question 2: How do I include Pagination correctly in my component? In my ngOnInit() I will have to integrate Pagination as well or?
Question 3: Currently I get "<jw-pagination [carGroups]="carGroups" (changePage)="onChangePage($event)">"
is not displayed. The div has the desired area at the end of the page but I don't see the PageController there. How can I make it visible?
According to the documentation, you should provide your data as items attribute like so:
<jw-pagination [items]="carGroups" (changePage)="onChangePage($event)"></jw-pagination>
This guide might be helpful.
https://edupala.com/how-to-implement-ionic-table-with-pagination/

ionic not load image from url wp-json and ionic4

when I connect ionic app with wordpress blog with wp-json all content loaded without image , I use ion-img
thanks
screenshot1
screenshot2
screenshot3
screenshot4
screenshot5
this is my code :
note : I use all in one security plugin on my wordpress blog
//post.service.ts
import { Injectable } from '#angular/core';
import { HttpClient } from "#angular/common/http";
import {Http, Headers, RequestOptions} from '#angular/http';
import { map } from "rxjs/operators";
import get from "lodash/get";
#Injectable({
providedIn: 'root'
})
export class PostsService {
constructor(private http: HttpClient) {}
private baseURL = "domain.com";
fetchPosts() {
return this.http
.get(`${this.baseURL}/wp-json/wp/v2/posts?_embed`)
.pipe(
map((posts: Array<any>) => posts.map(this.setEmbeddedFeaturedImage))
);
}
fetchPost(post_id: string) {
return this.http
.get(`${this.baseURL}/wp-json/wp/v2/posts/${post_id}?_embed`)
.pipe(map((post: any) => this.setEmbeddedFeaturedImage(post)));
}
/**
* Makes the featured image parameter easily accessible in a template
*/
private setEmbeddedFeaturedImage(p) {
return Object.assign({}, p, {
featured_image: get(p, "_embedded['wp:featuredmedia'][0].source_url")
});
}
fetchPostCategories() {
return this.http.get(`${this.baseURL}/wp-json/wp/v2/categories`);
}
fetchPostsByCategory(category_id: string) {
return this.http
.get(
`${this.baseURL}/wp-json/wp/v2/posts?_embed&categories=${category_id}`
)
.pipe(
map((posts: Array<any>) => posts.map(this.setEmbeddedFeaturedImage))
);
}
}
in the post view every thing loaded without the post images but the images url open in the browser
//home view :
<ion-header>
<ion-toolbar>
<ion-buttons slot="start">
<ion-menu-button></ion-menu-button>
</ion-buttons>
<ion-title>
title
</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-card class="welcome-card" (click)="loadPost(post)" padding-bottom *ngFor="let post of posts$ | async">
<img src="{{post.featured_image}}" >
<ion-card-header>
<ion-card-subtitle>{{post.title.rendered}}</ion-card-subtitle>
<ion-card-title>{{post.title.rendered}}</ion-card-title>
</ion-card-header>
<ion-card-content>
<div>
<div [innerHTML]="post.excerpt.rendered"></div>
</div>
<ion-button href="#">مشاهدة المزيد</ion-button>
</ion-card-content>
</ion-card>
</ion-content>
//
The problem has been resolved successfully for now, I found the problem from the firewall generated by the "All in one security plugin" of the wordpress , I am currently disabled the plugin
firewall roles until there is an exception option for the site's API.
Thanks
Now, is possible with this plugin.
Better Rest API
After you should used in the file .html
<ion-img [src]="noticia?.better_featured_image.media_details.sizes.medium.source_url">
</ion-img>
Regards

ionic runtime error - zone already loaded

I just wanted to use ionic 3 + firebase authentication. I followed the latest guidelines, youtube, documentation but i always encountered this problem when running 'ionic serve':
Error: Zone already loaded.
at http://localhost:8100/build/vendor.js:117672:15
at http://localhost:8100/build/vendor.js:118284:3
at FUNCTION (http://localhost:8100/build/vendor.js:117649:10)
at Object.<anonymous> (http://localhost:8100/build/vendor.js:117652:2)
at Object.<anonymous> (http://localhost:8100/build/vendor.js:120702:30)
at __webpack_require__ (http://localhost:8100/build/vendor.js:55:30)
at Object.defineProperty.value (http://localhost:8100/build/vendor.js:69145:66)
at __webpack_require__ (http://localhost:8100/build/vendor.js:55:30)
at Object.<anonymous> (http://localhost:8100/build/vendor.js:117167:72)
at __webpack_require__ (http://localhost:8100/build/vendor.js:55:30)
Ionic Framework: 3.9.2
Ionic App Scripts: 3.1.9
Angular Core: 5.2.10
Angular Compiler CLI: 5.2.10
Node: 9.11.1
OS Platform: Windows 8.1
Navigator Platform: Win32
User Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36
I have searched everything but nothing helps.
Thing i already did:
I follow everything from this link "Runtime Error Zone already loaded" in ionic 3 but it didn't solve my problem
I tried to remove 'import zone..' but could not find it. Searched the entire files but could not fine import zone. I got from this link How do I determine what zone is already loaded?
I could not find any solutions right now. Any suggestions given are appreciated.
My app.module.ts file
import { RegisterPage } from './../pages/register/register';
import { LoginPage } from './../pages/login/login';
import { CollectionPage } from './../pages/collection/collection';
import { BrowserModule } from '#angular/platform-browser';
import { ErrorHandler, NgModule } from '#angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import { ListPage } from '../pages/list/list';
import { StatusBar } from '#ionic-native/status-bar';
import { SplashScreen } from '#ionic-native/splash-screen';
import { AngularFireModule } from 'angularfire2';
import { AngularFireAuthModule } from 'angularfire2/auth';
const firebaseAuth = {
apiKey: "Axxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
authDomain: "fxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
databaseURL: "hxxxxxxxxxxxxxx",
projectId: "fxxxxxxxxxxxxx",
storageBucket: "firxxxxxxxxxxxx",
messagingSenderId: "xxxxxxxxx"
};
#NgModule({
declarations: [
MyApp,
HomePage,
CollectionPage,
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp),
AngularFireModule.initializeApp(firebaseAuth),
AngularFireAuthModule
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage,
CollectionPage,
],
providers: [
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler}
]
})
export class AppModule {
}
My register.html file
<ion-header>
<ion-navbar>
<ion-title>Register</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<ion-list>
<ion-item>
<ion-label>Username</ion-label>
<ion-input type="text" value=""></ion-input>
</ion-item>
<ion-item>
<ion-label>Password</ion-label>
<ion-input type="password" value=""></ion-input>
</ion-item>
</ion-list>
<div padding>
<button ion-button color="primary" block (click)="registerUser()">Register</button>
</div>
</ion-content>
My register.ts file
import { Component, ViewChild } from '#angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { AngularFireAuth } from 'angularfire2/auth';
#IonicPage()
#Component({
selector: 'page-register',
templateUrl: 'register.html',
})
export class RegisterPage {
#ViewChild('username') user;
#ViewChild('password') password;
constructor(private fire: AngularFireAuth, public navCtrl: NavController, public navParams: NavParams) {
}
ionViewDidLoad() {
console.log('ionViewDidLoad RegisterPage');
}
registerUser() {
this.fire.auth.createUserWithEmailAndPassword(this.user.value, this.password.value)
.then(data => {
console.log('got data ', data);
})
.catch(error => {
console.log('got an error ', error);
});
console.log('Would register user with ', this.user.value, this.password.value);
}
}
I had the exact problem today. It proves a problem of angularfire2
You can find the issue on github: Runtime Error Zone already loaded
Once I rollback to rc4, everything works properly, hope it helps.
npm install angularfire2#5.0.0-rc.4

How to display user data in modal

I am currently working on a project where there are two types of users: Drivers and Passengers. I am using Ionic Framework and Firebase Database ad Authentication. The Passengers are able to send requests to the drivers and the drivers are able to see these requests. I am currently working on the driver home page and creating a platform that lists the passenger's/customer's data and requests. I really want to user ionic modals to keep the information organized but I am unsure on how to go about this. I went ahead and attached the HTML and Javascript files for the Driver Home page and the modal page. Any help is extremely appreciated. This is my first time using Firebase and I am extremely lost.
My Database Structure
Driver Home Page
import { Component } from '#angular/core';
import { IonicPage, NavController, NavParams, ModalController, Modal } from 'ionic-angular';
import { DriverHomePage } from '../driver-home/driver-home';
import { CustomerModalPage } from '../customer-modal/customer-modal';
import { AngularFireAuth } from 'angularfire2/auth';
import { AngularFireDatabase, FirebaseListObservable } from 'angularfire2/database';
import * as firebase from 'firebase';
/**
* Generated class for the DriverHomePage page.
*
* See https://ionicframework.com/docs/components/#navigation for more info on
* Ionic pages and navigation.
*/
#IonicPage()
#Component({
selector: 'page-driver-home',
templateUrl: 'driver-home.html'
})
export class DriverHomePage {
const custRef = firebase.database().ref().child('User').orderByChild('type').equalTo('customer').once('value', function(snapshot) {
snapshot.forEach(function(child) {
var newCustomer = child.val();
var firstName=child.val().firstName;
var lastName=child.val().lastName;
var phone=child.val().phone;
var location = child.val().location;
var numOfPassengers = child.val().numOfPassengers;
var payment = child.val().payment;
});
});
constructor(private modalCtrl: ModalController, private afAuth: AngularFireAuth, private afDatabase: AngularFireDatabase, public navCtrl: NavController, public navParams: NavParams) {
}
openModal(){
//const custData
/* const custModal: Modal = this.modalCtrl.create('CustomerModalPage');
custModal.present();
custModal.onDidDismiss();*/
}
ionViewDidLoad() {
console.log('ionViewDidLoad DriverHomePage');
}
}
<!--
Generated template for the DriverHomePage page.
See http://ionicframework.com/docs/components/#navigation for more info on
Ionic pages and navigation.
-->
<ion-header>
<ion-navbar>
<button ion-button menuToggle>
<ion-icon name="menu"></ion-icon>
</button>
<ion-title>driver-home</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<button (click)"openModal()">{{ custRef.firstName }} {{ custRef.lastName }}</button>
</ion-content>
Modal
import { Component } from '#angular/core';
import { IonicPage, NavController, NavParams, ViewController } from 'ionic-angular';
import { AngularFire, FirebaseObjectObservable } from 'angularfire2';
import { AngularFireDatabase } from 'angularfire2/database';
import * as firebase from 'firebase';
/**
* Generated class for the CustomerModalPage page.
*
* See https://ionicframework.com/docs/components/#navigation for more info on
* Ionic pages and navigation.
*/
#IonicPage()
#Component({
selector: 'page-customer-modal',
templateUrl: 'customer-modal.html',
})
export class CustomerModalPage {
const custRef = firebase.database().ref().child(`User`).orderByChild('type').equalTo('customer').on('value', function(snapshot) {
snapshot.forEach(function(child) {
var datas = child.val();
var firstName=child.val().firstName;
var lastName=child.val().lastName;
var phone=child.val().phone;
var location = child.val().location;
var numOfPassengers = child.val().numOfPassengers;
var payment = child.val().payment;
});
});
constructor(private fb: AngularFire, private viewCtrl: ViewController, public navCtrl: NavController, public navParams: NavParams) {
}
acceptRequest(){
}
closeModal() {
this.viewCtrl.dismiss();
}
/*ionViewDidLoad() {
console.log('ionViewDidLoad CustomerModalPage');
}*/
ionViewWillLoad(){
//const data = this.navParams.get('data');
console.log();
}
}
<!--
Generated template for the CustomerModalPage page.
See http://ionicframework.com/docs/components/#navigation for more info on
Ionic pages and navigation.
-->
<ion-header>
<ion-navbar>
<ion-title>CustomerModalPage</ion-title>
<ion-buttons end>
<button ion-button (click)="closeModal()">Close</button>
</ion-buttons>
</ion-navbar>
</ion-header>
<ion-content padding>
<p>{{ custRef.firstName }}</p>
<p>{{ custRef.lastName }}</p>
<p>{{ custRef.phone }}</p>
<p>{{ custRef.location }}</p>
<p>{{ custRef.numOfPassengers }}</p>
<p>{{ custRef.payment }}</p>
<button (click)="acceptRequest()">Accept</button>
</ion-content>
I see you are using firebase library to access your database and I can also see you are importing angularfire2 too. I strongly recommend you use angularfire2 and avoid using firebase library as this is way easier. You can read more in the angularfire2 docs.
For your question, the best query would be something like this:
this.db.list('/user', ref => ref.orderByChild('type').equalTo('customer'))
.subscribe(users => {
users.forEach(user => {
//Do stuff with each user here.
})
});
Also, remember to inject the correct reference in your component. Your constructor should look like this:
constructor(db: AngularFireDatabase) { }

API data is not getting at first loading ionic2, angular2

I am struggling from last couple days.I am using ionic2/3 angular 2 and wordpress for data.
I am trying to load categories data at home page at first load but i am not getting. In browser it's coming properly and also when i click on menu button entire data is showing properly. I checked all blogs but didn't get any proper solution.
Please help me if any one had same issues and solved.Thanks in advance.
I am attaching my codes here.
enter code here
Home.ts-
import { Component } from '#angular/core';
import { NavController } from 'ionic-angular';
import * as WC from 'woocommerce-api';
#Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
woocommerce: any;
categories: any[];
// Home=HomePage;
constructor(public navCtrl: NavController) {
this.categories=[];
}
ionViewDidLoad(){
this.getCatData();
}
getCatData(){
this.woocommerce = WC({
url:'http://www.example.com/',
consumerKey: 'ck_7dfe0aec65ahgcdhgcdhcdhf36288d1fa2e4c01',
consumerSecret: 'cs_da53e5b228eb6235bshhcskhc7a68541ad809743'
});
this.woocommerce.getAsync("products/categories").then((data)=>{
console.log(JSON.parse(data.body).product_categories);
this.categories = JSON.parse(data.body).product_categories;
},(err)=>{
console.log(err);
})
}
}
Home.html-
<ion-header>
<ion-navbar color="header">
<ion-buttons left>
<button ion-button menuToggle>
<ion-icon name="menu"></ion-icon>
</button>
</ion-buttons>
<ion-buttons right>
<button ion-button icon-only>
<ion-icon name="search"></ion-icon>
</button>
</ion-buttons>
<ion-title>
KAAIROS EXPORTS
</ion-title>
</ion-navbar>
</ion-header>
<ion-content>
<!-- slider -->
<ion-card>
<ion-slides loop="true" autoplay="false" pager>
<ion-slide *ngFor= "let number of [1,2,3,4,5]"><img src="./assets/img/{{number}}.jpg"/></ion-slide>
</ion-slides>
</ion-card>
<!-- end-slider -->
<!-- <ion-grid> Hi this is second line
</ion-grid> -->
<ion-item *ngFor="let category of categories">
<h2> {{ category.name }} </h2>
</ion-item>
</ion-content>
app.component.ts-
import { TabsPage } from './../pages/tabs/tabs';
import { HomePage } from './../pages/home/home';
import { Component, ViewChild } from '#angular/core';
import { Nav, Platform } from 'ionic-angular';
import { StatusBar } from '#ionic-native/status-bar';
import { SplashScreen } from '#ionic-native/splash-screen';
//import { Menu } from '../pages/menu/menu';
#Component({
templateUrl: 'app.html'
})
export class MyApp {
#ViewChild(Nav) nav: Nav;
// rootPage: any = Menu;
rootPage = TabsPage;
constructor(public platform: Platform, public statusBar: StatusBar, public splashScreen: SplashScreen) {
this.initializeApp();
}
initializeApp() {
this.platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
this.statusBar.styleDefault();
this.splashScreen.hide();
});
}
// go_to_home(){
// this.nav.setRoot(HomePage);
// }
}
app.html-
<ion-menu side="left" [content]="content">
<ion-header>
<ion-toolbar>
<ion-title>Menu</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<!-- <ion-list>
<!-- <ion-item (click)="go_to_home()" menuClose>
Home
</ion-item> -->
<!-- <ion-item (click)="go_to_about()" menuClose>
About
</ion-item> -->
<!-- <ion-item (click)="go_to_contact()" menuClose>
Contact Us
<!-- </ion-item> -->
</ion-content>
</ion-menu>
<!-- Disable swipe-to-go-back because it's poor UX to combine STGB with side menus -->
<ion-nav [root]="rootPage" #content swipeBackEnabled="true"></ion-nav>
app.module:-
import { BrowserModule } from '#angular/platform-browser';
import { ErrorHandler, NgModule } from '#angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import { TabsPage } from '../pages/tabs/tabs';
import { AboutusPage } from '../pages/aboutus/aboutus';
import { ContactusPage } from '../pages/contactus/contactus';
import { CategoryPage } from '../pages/category/category';
import { ProductsByCategoryPage } from '../pages/products-by-category/products-by-category';
import { StatusBar } from '#ionic-native/status-bar';
import { SplashScreen } from '#ionic-native/splash-screen';
import { WooCommerceProvider } from '../providers/woocommerce/woocommerce';
import { HttpModule } from '#angular/http';
#NgModule({
declarations: [
MyApp,
HomePage,
TabsPage,
AboutusPage,
ContactusPage,
CategoryPage,
//ProductListPage,
ProductsByCategoryPage
],
imports: [
BrowserModule,
HttpModule,
IonicModule.forRoot(MyApp,{
mode:'ios'
}),
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage,
TabsPage,
AboutusPage,
ContactusPage,
CategoryPage,
ProductsByCategoryPage
],
providers: [
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler},
WooCommerceProvider
]
})
export class AppModule {}
Simply call the ChangeDetectorRef after successfull API call to refresh the changes in UI. PFB the sample code where we have triggered change detector on subscribe call. You can check the working version here
import { Component, ViewChild, ChangeDetectorRef } from '#angular/core';
import { NavController, Content } from 'ionic-angular';
#Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
#ViewChild(Content) content: Content;
Arr = Array; //Array type captured in a variable
num:number = 1000;
toolbar_color: string;
constructor(public navCtrl: NavController, public ref : ChangeDetectorRef) {
this.toolbar_color="secondary";
}
changeColor(){
this.toolbar_color="primary";
this.ref.detectChanges();
}
ionViewDidLoad() {
//this.content.enableJsScroll();
this.content.ionScrollEnd.subscribe(() => {
this.changeColor();
});
}
}
This is because your data is asynchronously loaded. The view has already been rendered by the time your data arrives.
One way to fix this is to add some kind of "refresh" method and call it when you receive the data (e.g., in .getAsync().then(...)).

Resources