Ionic nav-bar issue - ionic-framework

I am new to ionic framework
After i login to the app, i am redirecting to instance page.
In the instance page, i have a nav-bar enabled.
But i see nav-back button enabled and on refresh , i get back the nav-bar.
I tried adding
1 hide-nav-bar = false in instance page (no use)
2 hide-back-button= true in instane page (no use)
3 In the login controller, i tried adding
$ionicHistory.nextViewOptions({
disableBack: true
});
before i have
$state.go('instance'); (no use)
But when i refresh, from then on, it works fine.
Can someone help on this

You can use $ionicNavBarDelegate
In your controller
.controller('YourCtrl', function($ionicNavBarDelegate) {
$ionicNavBarDelegate.showBackButton(false);
})

Related

Ionic sidemenu not working after login, goes back to the login page instead

I have a login page where I disable the sidemenu with:
ionViewWillEnter() {
this.menuCtrl.enable(false);
}
ionViewDidLeave() {
this.menuCtrl.enable(true);
}
After logging in, I navigate to / which goes to /welcome:
this.router.navigate(['/']);
In /welcome, I have the menu turned on:
ionViewWillEnter() {
this.menuCtrl.enable(true);
}
Using Edge/Chrome, when I try to use the side-menu after logging in, it instead tries to "Go Back" to the login page:
Added: If I refresh the page after on /welcome, it reloads the page and fixes the sidemenu. So whatever is happening it seems like it must be left over from the login screen's functionality. Also, I thought adding ion-header fixed it, worked for about 2 logins then suddenly went back to it's previous behavior.
I've also noticed that if I sign out, the Angular authguard sends it back to /login, but if I try to swipe while on the login page, it tries to take me back to the app as though I was authenticated.. Then when I click on a link the Auth guard does it's job and sends be back to login again.
This time, I can still swipe left but a blank page tries to appear from the left instead - and this happens in desktop mode too.
Can anyone help me with this please?
I thought adding ion-header fixed it, it did at first, then suddenly started doing it again.
I finally ended up disabling Swipe within Ionic with:
IonicModule.forRoot({ swipeBackEnabled: false})
If anyone has any info it'd be appreciated.

Ionic content not updating after callback from external plugin

As part of the functionality of the app we are developing, when an android alarm is fired, a dialog box is to appear with an "Accept" or "Reject" button. Selecting reject does nothing, but selecting "Accept" triggers a callback from the plugin, which I have passed a function into. This function causes the ionic app to navigate to the root page of the app.
The issue I am having is, when I then navigate to another page after that where the user selects a value, and this value is displayed back to them and a button is enabled, the value display is not updating, and the button is not becoming enabled. Nothing seems to be updating.
What I have found is that pressing the back button on my android device will cause the page to update, which is not ideal.
This functionality works without the callback from the plugin.
What is happening here? And how do I fix it?
Passing the function into the plugin.
alarms_plugin.onAlarmRecieved = (alarmId) =>{
this.events.publish('alarmRecieved', alarmId);
}
Plugin-side functions
alarmRecieved: function(alarmId){
alarms_plugin.onAlarmRecieved(alarmId);
}
onAlarmRecieved: null
Navigating to root page on alarmRecieved
this.events.subscribe('alarmRecieved', (alarmId) =>{
if(alarmId != 'TIMEOUT')
this.nav.setRoot(HomePage);
});
Fix found by surrounding the this.nav.setRoot(HomePage) in this.zone.run(..).
Supposedly calling navigation within a subscription event causes issues like I was having.

Ionic deeplink shows blank page before the deeplink/page is pushed

I am using ionic deeplinks. I have a service where I initialize the deeplink function like:
initDeepLink(nav: Nav) {
this.deeplinks.routeWithNavController(nav, {
'/page1/ PageComponent1,
})
}...
I call this function in my main app.component.ts , inside onAllReady() function, from the service with:
this.calldeepLinkServ.initDeepLink(this.nav);
where this.nav is of type:
#ViewChild(Nav) nav: Nav;
declared in app.component.ts
When I visit a deeplink on my device, it works fine and goes to the given page (PageComponent1), but there is always a blank page before it and then the transition sort of jumps and push the deeplink page.
It never push (slide from right) the new page in the top of the current one opened in my app. I was trying to put the #ViewChild(Nav) nav: Nav inside the deeplink service rather the app.component.ts, but it acts the same.
I also tried to see if there is a method to disable the native page push in this.deeplinks.routeWithNavController() but it does not have any properties like that (like animate: false for example which is available for NavController).
So I am really not sure how to prevent this bad navigation experience with deeplinks i am sure that this is not a typical transition for ionic deeplinks, it looks bad for UI.
So I've sorted this one out, instead:
this.deeplinks.routeWithNavController
I am using:
this.deeplinks.route
and than i check what is passed on inside the match.$link. So depending on the query send through like
if (match.$link['path'].indexOf('/page1/') !== -1) {...}
I call the nav push, with animate:false and it does not uses the default nav push animation.

Ionic2 - Login and then Side menu

I am creating an App with Ionic2 and the requirement is -
- the app when first loaded will show a Log In page and when logged in
- will have a Side-Menu enabled pages
The starter project shows that the Side Menu as the root of the app and loads first before any other page is open - then it loads the other related pages.
How can I build an app that Loads Log In page first and then set the Side Menu as the main navigation and never shows up the Log In screen??
I did this with ionic 1 but not being able to figure out with ionic2
Please help.
One solution would be to disable menu on Login screen and then to enable it after login.
You can disable menu by injecting MenuController and then use:
import {NavController, MenuController} from 'ionic-angular';
ionViewDidEnter() {
//to disable menu, or
this.menu.enable(false);
}
ionViewWillLeave() {
// to enable menu.
this.menu.enable(true);
}
#Digital IQ, you have to set your login page as the rootPage in your existing app.ts file and use MenuController in login page to make menu enable onPageDidLeave.
The example for this is available in ionic conference app where they have tutorial page before getting in to the actual application. Refer this for menu control and this (line 50) to set the initial page.
The above problem must have occurred because the user had surely logged in, but the changes i.e. setting it as the current user didn't take place in side menu page.
For that you can use Events API
Events is a publish-subscribe style event system for sending and responding to application-level events across your app.
For reference, go through the following answer-
Ionic 3 refresh side menu after login
kind Attn [vahid najafi & Aish123]
I tried something more easy and I found it working.
I set the LogIn page as the root when the app first loaded - and I removed 'menuToggle' button from this template.
Then I imported the Component I want to redirect on Log in
I created a singIn function in LogInPage class as follows:
signIn (){
let navRef = this.app.getComponent('nav');
navRef.setRoot(HelloIonicPage);
}
and it worked like a charm

back-button doesn't work properly ionic famework

I have this flow in my ionic app... login.html page(which is a "ion-view")->side-menu page(side-menu from ionic framework)->page2.html page(which is a "ion-view"). Now i want to implement "ion-nav-bar" with "ion-nav-back-button" in it. Normally when i want to go back from page2.html the app should sent me to side-menu page....instead, my app, sent me to login page. Seems like side-menu does not have "ion-view" in it and it is not recorded in app flow. Any suggestion how can i solve that ? thank you
There is no a state for side menu, you can not 'go back' to open side menu.
In the normal, for the login view, you should disable the state temporally. Then the app will not 'go back' to login view. You can do it like this:
$scope.doLogin = function () {
Auth.login($scope.loginData, function () {
console.log('login success');
$ionicHistory.nextViewOptions({
disableBack: true
});
$state.go('home');
});
};
And you can also clear the view history of ionic to avoid going back with:
$ionicHistory.clearHistory();
$state.go('user.home');