Trying to figure out this problem. I am getting a maxmimum call stack size error and the link below is the js output.
I have added print statements and worked out the main app file is calling page1 as it should but then page1 is calling the main app file and this continues.
I am new to ionic 2 and would really appreciate a solution, thanks.
Javascript Output
page1.ts
import { Component } from '#angular/core';
import { Data } from '../../providers/data';
import { NewListPage } from '../new-list/new-list';
import { NavController } from 'ionic-angular';
#Component({
selector: 'page-page1',
templateUrl: 'page1.html',
})
export class Page1 {
public list: any[] = [];
constructor(public navCtrl: NavController, private _data: Data) {
console.log('Page1BEFORE');
let that = this;
this._data.list.subscribe((data) => {that.list.push(data);}, (err) => {console.error(err);});
}
newList() {
console.log('NEWLIST1');
this.navCtrl.push(NewListPage);
}
}
page1.html
<ion-app>
<ion-header>
<ion-navbar>
<button ion-button menuToggle>
<ion-icon name="menu"></ion-icon>
</button>
<ion-title>Page One</ion-title>
<ion-buttons end>
<ion-icon ios="ios-contact" md="md-contact"></ion-icon>
</ion-buttons>
</ion-navbar>
</ion-header>
<ion-content class="grid-basic-page">
<ion-col width-100><progress class="progressBar" max="100" value="80"></progress></ion-col>
<ion-row>
<ion-col width-50><div>col</div></ion-col>
<ion-col width-50><div>col</div></ion-col>
</ion-row>
<ion-row>
<ion-col width-50><div>col</div></ion-col>
<ion-col width-50><div>col</div></ion-col>
</ion-row>
<ion-row>
<ion-col width-50><div>col</div></ion-col>
<ion-col width-50><div>col</div></ion-col>
</ion-row>
<ion-list *ngIf="list">
<ion-item *ngFor="let item of list">
<ion-label>{{item.title}}</ion-label>
</ion-item>
</ion-list>
<p *ngIf="!list"> No Lists </p>
<button fab fab-bottom fab-right (click)="newList()"> New </button>
</ion-content>
</ion-app>
app.component.ts
import { Component, ViewChild } from '#angular/core';
import { Nav, Platform } from 'ionic-angular';
import { StatusBar, Splashscreen } from 'ionic-native';
import { Page1 } from '../pages/page1/page1';
import { Page2 } from '../pages/page2/page2';
import { Data } from '../providers/data';
#Component({
templateUrl: 'app.html',
providers: [Data],
})
export class MyApp {
#ViewChild(Nav) nav: Nav;
rootPage: any = Page1;
pages: Array<{title: string, component: any}>;
constructor(public platform: Platform) {
console.log('PreAPP');
this.initializeApp();
console.log('PostApp');
// used for an example of ngFor and navigation
this.pages = [
{ title: 'Page One', component: Page1 },
{ title: 'Page Two', component: Page2 }
];
console.log('pages');
}
initializeApp() {
console.log('APP');
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.
StatusBar.styleDefault();
Splashscreen.hide();
});
}
openPage(page) {
console.log('OpenPAGE');
// Reset the content nav to have just this page
// we wouldn't want the back button to show in this scenario
this.nav.setRoot(page.component);
}
}
app.html
<ion-menu [content]="content">
<ion-header>
<ion-toolbar>
<ion-title>Menu</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-list>
<button menuClose ion-item *ngFor="let p of pages" (click)="openPage(p)">
{{ p.title }}
</button>
</ion-list>
</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="false"></ion-nav>
Removing the <ion-app> element from page1.html fixed the issue
In my case I had not declared and added routes constant in imports array of the module. Once declared and imported error gone.
I am using IONIC 4
Related
I would like to set a button that opens and hides some ion-item in a dropdown.
I know that there might be a solution in the docs but I am unable to find it
<ion-header>
<ion-toolbar>
<ion-title>Technical Information</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-list>
<ion-list-header>
<ion-label>Manuales</ion-label>
</ion-list-header>
<ion-item *ngFor="let m of manuals">
<ion-label>{{m}}</ion-label>
</ion-item>
</ion-list>
<!-- Other <ion-list-header>s and <ion-item>s -->
</ion-content>
I would like to hide and show all Items when clicking on each ion-list-header, show his own ion-item with *ngFor, like if there are 20 manuals, dropdown all 20 manuals and hide others ion-list-headers...
Is there a way to do it with this structure or maybe with another?
Try this:
<ion-header>
<ion-toolbar>
<ion-title>Technical Information</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-list *ngFor="let m of manuals; let i=index">
<ion-list-header>
<ion-label (click)="showOrHide(i)">Manuales</ion-label>
</ion-list-header>
<ion-list id="{{i}}" style="display:none">
<ion-item *ngFor="let m of m.list">
<ion-label>{{m}}</ion-label>
</ion-item>
</ion-list>
</ion-list>
</ion-content>
In .ts component:
import { Component } from '#angular/core';
import { NavController , AlertController } from 'ionic-angular';
#Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
manuals = [{
id:1,
list: ["1","2","3"]
},
{
id:2,
list: ["1","2","3"]
},
{
id:3,
list: ["1","2","3"]
},
{
id:4,
list: ["1","2","3"]
}]
constructor() {
}
showOrHide(id){
const listItemShow = document.getElementById(id);
if(listItemShow.style.display === "none")
listItemShow.style.display = "block"
else
listItemShow.style.display = "none"
}
}
I have been struggling with ion-checkboxes and I really need some help. I am developing a questionnaire that has true or false answers. I want the true and false to appear as ion-checkboxes. Something like this
<ion-row>
<ion-col size="1">
<ion-checkbox [checked]="option1" (ionChange)=change1()>
</ion-checkbox>
</ion-col>
<ion-col>True </ion-col>
<ion-col size="1">
<ion-checkbox [checked]="option2" (ionChange)=change1()>
</ion-checkbox>
</ion-col>
<ion-col>False </ion-col>
</ion-row>
I want the ionChange to ensure that only one checkbox is checked as true at a time. In other worlds, if the user selects true, then the false checkbox (option2) will automatically become false. If anyone can help I would really appreciate it.
Here is the simple way to do it
https://stackblitz.com/edit/ionic-a51emq
Home.ts
import { Component } from '#angular/core';
import { NavController } from 'ionic-angular';
#Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
avengers = {
stark: true,
steve: false
}
constructor(public navCtrl: NavController) {
}
filterData(){
this.avengers.steve = !this.avengers.steve
this.avengers.stark = !this.avengers.stark
}
}
Home.html
<ion-header>
<ion-navbar>
<ion-title>Home</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<ion-card padding>
<ion-checkbox [checked]="avengers.stark" ([ngModel])='avengers.stark' (click)="filterData()"></ion-checkbox> Stark
</ion-card>
<ion-card padding>
<ion-checkbox [checked]="avengers.steve" ([ngModel])='avengers.steve' (click)="filterData()">Stark</ion-checkbox> Steve
</ion-card>
</ion-content>
Is there a way to implement the ion-back-button without having it automatically trigger nav.pop() ?
The problem stems form the funny custom arrow-back button ionic uses which I can't simply remake.
The snippet below is the closest and simplest approach but the result does not look "identical". It doesn't doesn't automatically hide when the nav stack is empty.
<ion-button slot="start" (click)="onBack()" fill="clear">
<ion-icon slot="icon-only" name="arrow-back" style="color:#424242"></ion-icon>
</ion-button>
What I would like is
<ion-back-button slot="start" (click)="someCustomLogic()"></ion-back-button>
Definitely a hack:
<ion-toolbar>
<ion-buttons slot="start">
<ion-back-button onclick="event.stopImmediatePropagation(); window.myCustomMethod()"></ion-back-button>
</ion-buttons>
<ion-title>
List
</ion-title>
</ion-toolbar>
Inside ts:
import { Component, OnInit } from '#angular/core';
import { NavController } from '#ionic/angular';
#Component({
selector: 'app-list',
templateUrl: 'list.page.html',
styleUrls: ['list.page.scss']
})
export class ListPage {
constructor( private navCtrl: NavController) {
window['myCustomMethod'] = this.overide;
}
overide = () => {
console.log("hi")
this.navCtrl.navigateBack('/home')
}
}
Why don't your try something like that :
<ion-row>
<ion-col tap="someCustomLogic()">
<ion-icon slot="icon-only" name="arrow-back" style="color:#424242"></ion-icon>
</ion-col>
</ion-row>
I'm new to ionic. I have a component called firstPage, this has a normal html view.
<ion-header>
<ion-navbar >
<ion-title align="center">first.</ion-title>
</ion-navbar>
</ion-header>
<button ion-button
block
color="primary"
[navPush]="second">
Ir página 2 navPush.
</button>
</ion-content>
import { Component } from '#angular/core';
import { NavController, NavParams } from 'ionic-angular';
import { secondPage} from '../index.paginas';
#Component({
selector: 'page-first',
templateUrl: 'first.html',
})
export class firstPage {
constructor(public navCtrl: NavController, public navParams: NavParams) {
}
second:any=secondPage;
}
and I have another component called secondPage.
<ion-header>
<ion-navbar>
<ion-title align-title="center">second</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
esta es la segunda XDDD
<button ion-button block color="primary" navPop>back</button>
<!--<page-tabs></page-tabs>-->
</ion-content>
import { Component } from '#angular/core';
import { NavController, NavParams } from 'ionic-angular';
import { firstPage, Tab1Page,Tab2Page} from '../index.paginas';
#Component({
selector: 'page-second',
templateUrl: 'second.html',
})
export class secondPage {
Tab1Page,Tab2Page // are the component that has html and .ts
tab1: any;
tab2: any;
constructor() {
this.tab1 = Tab1Page;
this.tab2 = Tab2Page;
}
}
firstPage has a button to navigate directly to secondPage, but I want SecondPage to contain :
<ion-tabs color="primary" selectedIndex="1">
<ion-tab tabIcon="hammer" tabTitle="Tab2" [root]="tab1">tab1</ion-tab>
<ion-tab tabIcon="hammer" tabTitle="Tab1" [root]="tab2">tab2</ion-tab>
</ion-tabs>
I want the second page to load the tabs only in this view
how can I do it?
Add tabs to second-page.html.
<ion-tabs color="primary" selectedIndex="1">
<ion-tab tabIcon="hammer" tabTitle="Tab2" [root]="tab1"></ion-tab>
<ion-tab tabIcon="hammer" tabTitle="Tab1" [root]="tab1"></ion-tab>
</ion-tabs>
Your SecondPage.ts class is OK. Only thing you need to do is add below code to your html which related with your Tab2Page.ts.
<ion-content padding>
esta es la segunda XDDD
<button ion-button block color="primary" navPop>back</button>
</ion-content>
I created a demo for you. find it here
I am developing an IONIC-3 application, whether I want a dynamic nav bar with a title and a common button. For this reason, I have created a .ts file named
commonBtn.ts. Here is the code.
import { Component } from '#angular/core';
import { NavController } from 'ionic-angular';
import { LoginPage } from '../login/login';
#Component({
selector: 'common-button',
templateUrl: 'commonBtn.html'
})
export class CommonBtnPage {
constructor(public navCtrl: NavController) { }
logOut() {
this.navCtrl.setRoot(LoginPage);
}
}
And its html is :-
<ion-header>
<ion-navbar>
<ion-title> I want to create a dynamic name </ion-title>
<ion-buttons end>
<button ion-button icon-only (click)="logOut()">
<ion-icon name="log-out"></ion-icon>
</button>
</ion-buttons>
</ion-navbar>
</ion-header>
Now, my question is that, How may I change the title name dynamically means when user come into "Home Page", title will be "Home" or user come into "About" page, title will be "About".
We can manage this in ionic v1 via $rootScope but here in Ionic v3, how can I resolve this ?
Also I am giving the html of Home page
<ion-header>
<ion-navbar>
<ion-title>Home</ion-title>
<common-button></common-button>
</ion-navbar>
</ion-header>
<ion-content padding>
<button ion-button (click) = 'clickHere()'> Click </button>
</ion-content>
Please suggest me what to do.
Generally, you need to use Input decorator. Check Component Interactions.
In CommonBtnPage,
import { Component,Input } from '#angular/core';
import { NavController } from 'ionic-angular';
import { LoginPage } from '../login/login';
#Component({
selector: 'common-button',
templateUrl: 'commonBtn.html'
})
export class CommonBtnPage {
#Input()title:string;//here
constructor(public navCtrl: NavController) { }
logOut() {
this.navCtrl.setRoot(LoginPage);
}
}
In the html, set the title,
<ion-header>
<ion-navbar>
<ion-title>{{title}}</ion-title>
<ion-buttons end>
<button ion-button icon-only (click)="logOut()">
<ion-icon name="log-out"></ion-icon>
</button>
</ion-buttons>
</ion-navbar>
</ion-header>
You can set the component and send the title as:
<common-button [title]="'home'"></common-button>