Ionic and Angular: Routing not working - angularjs

I have an Ionic sidemenu project with the following menu:
<ion-side-menus enable-menu-with-back-views="false">
<ion-side-menu-content>
<ion-nav-bar class="bar-stable" align-title="center">
<ion-nav-back-button>
</ion-nav-back-button>
<ion-nav-buttons side="left">
<button class="button button-icon button-clear ion-navicon" menu-toggle="left">
</button>
</ion-nav-buttons>
</ion-nav-bar>
<ion-nav-view name="menuContent"></ion-nav-view>
</ion-side-menu-content>
<ion-side-menu side="left">
<ion-content>
<div class="list">
<a class="item item-icon-left" menu-close href="#/app/products">
<i class="icon ion-home"></i>
<h2>Home</h2>
</a>
<a class="item item-icon-left" menu-close href="#/app/account">
<i class="icon ion-person"></i>
<h2>mein Konto</h2>
</a>
<a class="item item-icon-left" menu-close href="#/app/orders">
<i class="icon ion-android-list"></i>
<h2>meine Bestellungen</h2>
</a>
</div>
</ion-content>
</ion-side-menu>
</ion-side-menus>
The hrefs defined here are all working as intended.
My products page now has several sub-pages.
Html-File:
<ion-view view-title="Home">
<ion-content>
<ion-list>
<ion-item ng-repeat="product in products" href="#/app/products/{{product.templateUrl}}">
{{product.name}}
</ion-item>
</ion-list>
</ion-content>
</ion-view>
JS-File:
angular.module('App.Products', ['App.Products.Prints', 'App.Products.Box', 'App.Products.Book', 'App.Products.Framed'])
.config(function ($stateProvider, $urlRouterProvider) {
$stateProvider.state('app.products', {
url: "/products",
views: {
'menuContent': {
templateUrl: "modules/products/products.html",
controller: 'ProductsController'
}
}
});
})
.controller('ProductsController', function ($scope, ProductsFactory) {
$scope.products = [];
init();
function init() {
$scope.products = ProductsFactory.getProducts();
}
})
.factory('ProductsFactory', function() {
var products = [
{
name: 'Prints',
img: 'img/wardwarz.png',
templateUrl: 'prints'
},
{
name: 'PhotoBox',
img: 'img/argo.png',
templateUrl: 'box'
},
{
name: 'Photobuch',
img: 'img/django.png',
templateUrl: 'book'
},
{
name: 'Photo im Rahmen',
img: 'img/ic_profile.png',
templateUrl: 'framed'
}
];
var factory = {};
factory.getProducts = function () {
// Hier könnte ein HTTP Request rein um die Produkte vom Server zu erhalten!
return products;
}
return factory;
});
and to show one example one content of a sub page:
Html-File:
<ion-view view-title="Prints">
<ion-content>
</ion-content>
</ion-view>
JS-File:
angular.module('App.Products.Prints', [])
.config(function ($stateProvider, $urlRouterProvider) {
$stateProvider.state('app.products.prints', {
url: "/products/prints",
views: {
'menuContent': {
templateUrl: "modules/products/prints/prints.html"
}
}
});
});
When i now start the app ionic serve the navigation of the sidemenu works fine and i can open my products page. The navigation to prodcuts/prints does not work. I dont get an error message or anything. There is just nothing happening after the click on the item.
Whats going worng here?
An example Project can be found here: Mega File - MyApp.rar

Instead of using only href to do your navigation use
ui-sref="name_of_the_state"
Example:
ui-sref="app.products.prints"
This way you will not have issues with your navigation on angular/ionic.
If you even have a parameter in your route, like:
$stateProvider.state('app.products.edit', {
url: "/products/edit/:id",
views: {
'menuContent': {
templateUrl: "modules/products/prints/prints.html"
}
}
});
you can use:
ui-sref="app.products.edit(1)"
Also, I'm not seeying an abstract route on this, the app. It should be like:
app -> abstract
app.products
app.products.prints
I was able to simulate the error on my PC.
When you work with nested states you like app.products.print you need a intermediary view like this:
Example from a code I have on my pc that is working:
.state("admin", {
url: "/admin",
abstract: true,
views: {
"body": { templateUrl: "partials/_layoutAdmin.html" }
}
})
.state("admin.page", {
url: "/page/:idEdition",
abstract: true,
views: {
"header": { templateUrl: "partials/header.html", controller: "DefaultHeaderController" },
"content": { templateUrl: "partials/_layoutAdminEdition.html" }
}
})
.state("admin.page.create", {
url: "/create",
views: {
"content": { templateUrl: "partials/admin.page.form.html", controller: "PageFormController" }
}
})
Example of Templates
The main layout has thi
<div data-ui-view="body"></div>
The _layoutAdmin has this one
<header data-ui-view="header"></header>
<div class="container-fluid">
<div class="row">
<div data-ui-view="content"></div>
</div>
</div>
When the code enters the admin state it will load this first piece...
THEN...
<div data-ui-view="content" class="edition-form"></div>
AND THEN... the form CODE
So, in your case, you have app.products.prints:
app -> need a view -> ok you got it
app.products -> also need a view -> ok you got it
app.products.prints -> inside app.products view (products.html) you need a to show this inside it.
For simplicity, I suggest you to change it's name to app.productsPrint (without the "." and you'll be able to do it the way you are doing it right now with no impact.
Made some changes on the code you provided:
<ion-view view-title="Home">
<ion-content>
<div ui-view="myTestContent"></div>
</ion-content>
</ion-view>
Notice the ui-view="myTestContent"
and
.state('app.products.prints', {
url: "/prints",
views: {
'myTestContent': {
templateUrl: "modules/products/prints/prints.html"
}
}
});
and it worked.
So, in your case I recommend you to use productPrints instead of products.print. This nesting is used in those view inside view scenarios.

Related

ionic hide menu button but keep back button

I am working on a ionic framework app, where i need to hide only menu button on a specific template but need to keep back button.
it is showing like
My app.js
// setup an abstract state for the tabs directive
.state('app', {
url: '/app',
cache: false,
abstract: true,
templateUrl: 'templates/menu.html',
})
.state('app.home', {
url: '/home',
cache: false,
views: {
'menuContent': {
templateUrl: 'templates/home.html',
controller: 'DashCtrl'
}
}
})
.state('app.models', {
url: '/models',
cache: false,
views: {
'menuContent': {
templateUrl: 'templates/models.html',
controller: 'ModelCtrl'
}
}
})
.state('app.model', {
url: '/model/:Id',
cache: false,
views: {
'menuContent': {
templateUrl: 'templates/models-data.html',
controller: 'ModeldataCtrl'
}
}
})
.state('app.models-detail', {
url: '/models/:Id',
cache: false,
views: {
'menuContent': {
templateUrl: 'templates/single-model.html',
controller: 'ModelDetailCtrl'
}
}
})
.state('app.about', {
url: '/about',
cache: false,
views: {
'menuContent': {
templateUrl: 'templates/about.html',
controller: 'AboutCtrl'
}
}
});
// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise('/app/home');
});
Menu html is:
<ion-side-menus enable-menu-with-back-views="true">
<ion-side-menu-content>
<ion-nav-bar class="bar-stable">
<ion-nav-back-button>
</ion-nav-back-button>
<ion-nav-buttons side="left">
<button class="button button-icon button-clear ion-navicon" menu-toggle="left">
</button>
</ion-nav-buttons>
</ion-nav-bar>
<ion-nav-view name="menuContent"></ion-nav-view>
</ion-side-menu-content>
<ion-side-menu side="left">
<ion-header-bar class="bar-stable">
<h1 class="title">Rolls</h1>
</ion-header-bar>
<ion-content>
<ion-list>
<ion-item menu-close href="#/app/home">
Home
</ion-item>
<ion-item menu-close href="#/app/models">
Models
</ion-item>
<ion-item menu-close href="#/app/about">
About
</ion-item>
</ion-list>
</ion-content>
</ion-side-menu>
</ion-side-menus>
single-model html page where i am getting both menu and back button code are : single-model.html
<ion-view view-title="{{models.title}}">
<ion-content class="padding" overflow-scroll="true">
<img ng-src="{{models.image}}" style="width: 64px; height: 64px">
<p>
{{models.subtitle}}
</p>
</ion-content>
</ion-view>
Model and single model controller code is :
.controller('ModeldataCtrl', function($rootScope,$scope,$ionicLoading,$timeout, $stateParams, Models) {
$rootScope.dataloarding();
Models.modeldata($stateParams.Id).success(function(result){
if(result.success =='1'){
$scope.modeldata = result.data;
$rootScope.hideloading();
}
})
.error(function(result)
{
$rootScope.hideloading();
$rootScope.showAlert("Internet Connection Error");
});
})
.controller('ModelDetailCtrl', function($rootScope,$scope,$ionicLoading,$timeout, $stateParams,$ionicSideMenuDelegate, Models) {
$ionicSideMenuDelegate.canDragContent(false);
$rootScope.dataloarding();
Models.singlemodel($stateParams.Id).success(function(result){
if(result.success =='1'){
$scope.models = result.data;
$rootScope.hideloading();
}
})
.error(function(result)
{
$rootScope.hideloading();
$rootScope.showAlert("Internet Connection Error");
});
})
i follow this and this but it remove both back button and menu both or back button only.
Is there any solution to remove only menu from single-model html page only ?
This worked for me:
<ion-view view-title="Register">
<!-- to remove sidemenu button -->
<ion-nav-bar>
<ion-nav-back-button>
</ion-nav-back-button>
</ion-nav-bar>
...
I just added a simple nav-bar. The sidemenu button is gone and I kept the back button.
You can try this, it works for me. Replace your side menu content with below code
<ion-pane ion-side-menu-content>
<ion-nav-bar class="bar-stable">
<ion-nav-back-button class="button-clear"><i class="icon ion-chevron-left"></i> Back</ion-nav-back-button>
</ion-nav-bar>
<ion-nav-view name="menuContent" animation="slide-left-right"></ion-nav-view>

Not able to replace the view with <ion-nav-view>

Not able to replace the view in ionic with . I have menu in form of buttons when I click them the view is not getting replaces.Below is the code I have tried
**index.html**
<div class="button-bar">
<a class="button button-small button-stable button-outline" ui-sref="page1">Page1</a>
<a class="button button-small button-stable button-outline" ui-sref="page2">Page2</a>
<a class="button button-small button-stable button-outline" ui-sref="page3">Page3</a>
</div>
<ion-nav-view name="page1"></ion-nav-view>
<ion-nav-view name="page2"></ion-nav-view>
<ion-nav-view name="page3"></ion-nav-view>
The js files used to replace the view.In page.controller.js nothing is theres. Just declared with app.controller and nothing is there.
**pages.js**
app.config(function($stateProvider, $urlRouterProvider) {
$stateProvider.state('page1', {
cache: false,
parent:'app',
views: {
'page1': {
templateUrl: 'templates/page1.html',
controller: 'pages.controller'
}
}
}).state('page2', {
cache: false,
parent:'app',
views: {
'page2': {
templateUrl: 'templates/page2.html',
controller: 'pages.controller'
}
}
}).state('page3', {
cache: false,
parent:'app',
views: {
'page3': {
templateUrl: 'templates/page1.html',
controller: 'pages.controller'
}
}
})
});
The below are the html pages for the views.
page1.html
<ion-view view-title="page1">
<ion-content>
<div> <h2> Welcome to Page 1</h2> </div>
</ion-view>
</ion-content>
page2.html
<ion-view view-title="page2">
<ion-content>
<div> <h2> Welcome to Page 2</h2> </div>
</ion-view>
</ion-content>
page3.html
<ion-view view-title="page3">
<ion-content>
<div> <h2> Welcome to Page 3</h2> </div>
</ion-view>
</ion-content>
app.js
var app = angular
.module(
'sampleapp',
[ 'ionic' ]).config(
function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('app', {
cache : false,
url : "/app",
abstract:true,
templateUrl : "templates/index.html",
controller : 'appcontroller'
})
Kindly, help me understand why the view is not getting replaced.
this is likely because you have 3 different ion-nav-view tags, and each one of them having a separate name, along with each state only replacing its specific tag name.
Which means even if your views are injected, they will overlap (and probably why you're not seeing your views change, as theyre overlapping).
You should change:
index.html
<div class="button-bar">
<a class="button button-small button-stable button-outline" ui-sref="page1">Page1</a>
<a class="button button-small button-stable button-outline" ui-sref="page2">Page2</a>
<a class="button button-small button-stable button-outline" ui-sref="page3">Page3</a>
</div>
<ion-nav-view name="page-content"></ion-nav-view>
pages.js
app.config(function($stateProvider, $urlRouterProvider) {
$stateProvider.state('page1', {
cache: false,
parent:'app',
views: {
'page-content': {
templateUrl: 'templates/page1.html',
controller: 'pages.controller'
}
}
}).state('page2', {
cache: false,
parent:'app',
views: {
'page-content': {
templateUrl: 'templates/page2.html',
controller: 'pages.controller'
}
}
}).state('page3', {
cache: false,
parent:'app',
views: {
'page-content': {
templateUrl: 'templates/page1.html',
controller: 'pages.controller'
}
}
})
});

Adding slideshow to the ionic side menu starter app is not working

I am a novice to ionic and AngularJS so suspect I am doing something stupid but can't for the life of me work out what. I am using the ionic starter template for a side menu app. I have added another menu item for a 'new home' page. Into this page I have added some code from the ionic code pen example for an introduction slide show. Unfortunately I only get an empty page rather than the slide show.
My home.html template looks like this:
<script id="templates/home.html" type="text/ng-template">
<ion-view view-title="Intro">
<ion-nav-buttons side="left">
<button class="button button-positive button-clear no-animation" ng-click="startApp()" ng-show="!slideIndex">
Skip Intro
</button>
<button class="button button-positive button-clear no-animation" ng-click="previous()" ng-show="slideIndex > 0">
Previous Slide
</button>
</ion-nav-buttons>
<ion-nav-buttons side="right">
<button class="button button-positive button-clear no-animation" ng-click="next()" ng-show="slideIndex != 2">
Next
</button>
<button class="button button-positive button-clear no-animation" ng-click="startApp()" ng-show="slideIndex == 2">
Start using MyApp
</button>
</ion-nav-buttons>
<ion-slide-box on-slide-changed="slideChanged(index)">
<ion-slide>
<h3>Thank you for choosing the Awesome App!</h3>
<div id="logo">
<img src="http://code.ionicframework.com/assets/img/app_icon.png">
</div>
<p>
We've worked super hard to make you happy.
</p>
<p>
But if you are angry, too bad.
</p>
</ion-slide>
<ion-slide>
<h3>Using Awesome</h3>
<div id="list">
<h5>Just three steps:</h5>
<ol>
<li>Be awesome</li>
<li>Stay awesome</li>
<li>There is no step 3</li>
</ol>
</div>
</ion-slide>
<ion-slide>
<h3>Any questions?</h3>
<p>
Too bad!
</p>
</ion-slide>
</ion-slide-box>
</ion-view>
My app.js looks like this:
angular.module('starter', ['ionic', 'starter.controllers'])
.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);
cordova.plugins.Keyboard.disableScroll(true);
}
if (window.StatusBar) {
// org.apache.cordova.statusbar required
StatusBar.styleDefault();
}
});
})
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('app', {
url: '/app',
abstract: true,
templateUrl: 'templates/menu.html',
controller: 'AppCtrl'
})
// :NEW: Added stuff to show a home page
.state('app.home', {
url: '/home',
views: {
'menuContent': {
templateUrl: 'templates/home.html',
controller: 'IntroCtrl'
}
}
})
.state('app.search', {
url: '/search',
views: {
'menuContent': {
templateUrl: 'templates/search.html'
}
}
})
.state('app.browse', {
url: '/browse',
views: {
'menuContent': {
templateUrl: 'templates/browse.html'
}
}
})
.state('app.playlists', {
url: '/playlists',
views: {
'menuContent': {
templateUrl: 'templates/playlists.html',
controller: 'PlaylistsCtrl'
}
}
})
.state('app.single', {
url: '/playlists/:playlistId',
views: {
'menuContent': {
templateUrl: 'templates/playlist.html',
controller: 'PlaylistCtrl'
}
}
});
// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise('/app/playlists');
});
My controllers.js looks like this:
angular.module('starter.controllers', [])
.controller('AppCtrl', function($scope, $ionicModal, $timeout) {
// With the new view caching in Ionic, Controllers are only called
// when they are recreated or on app start, instead of every page change.
// To listen for when this page is active (for example, to refresh data),
// listen for the $ionicView.enter event:
//$scope.$on('$ionicView.enter', function(e) {
//});
// Form data for the login modal
$scope.loginData = {};
// Create the login modal that we will use later
$ionicModal.fromTemplateUrl('templates/login.html', {
scope: $scope
}).then(function(modal) {
$scope.modal = modal;
});
// Triggered in the login modal to close it
$scope.closeLogin = function() {
$scope.modal.hide();
};
// Open the login modal
$scope.login = function() {
$scope.modal.show();
};
// Perform the login action when the user submits the login form
$scope.doLogin = function() {
console.log('Doing login', $scope.loginData);
// Simulate a login delay. Remove this and replace with your login
// code if using a login system
$timeout(function() {
$scope.closeLogin();
}, 1000);
};
})
.controller('IntroCtrl', function($scope, $state, $ionicSlideBoxDelegate) {
$scope.next = function() {
$ionicSlideBoxDelegate.next();
};
$scope.previous = function() {
$ionicSlideBoxDelegate.previous();
};
// Called each time the slide changes
$scope.slideChanged = function(index) {
$scope.slideIndex = index;
};
})
.controller('PlaylistsCtrl', function($scope) {
$scope.playlists = [
{ title: 'Reggae', id: 1 },
{ title: 'Chill', id: 2 },
{ title: 'Dubstep', id: 3 },
{ title: 'Indie', id: 4 },
{ title: 'Rap', id: 5 },
{ title: 'Cowbell', id: 6 }
];
})
.controller('PlaylistCtrl', function($scope, $stateParams) {
});
The menu.html looks like this:
<ion-side-menus enable-menu-with-back-views="false">
<ion-side-menu-content>
<ion-nav-bar class="bar-stable">
<ion-nav-back-button>
</ion-nav-back-button>
<ion-nav-buttons side="left">
<button class="button button-icon button-clear ion-navicon" menu-toggle="left">
</button>
</ion-nav-buttons>
</ion-nav-bar>
<ion-nav-view name="menuContent"></ion-nav-view>
</ion-side-menu-content>
<ion-side-menu side="left">
<ion-header-bar class="bar-stable">
<h1 class="title">Left</h1>
</ion-header-bar>
<ion-content>
<ion-list>
<ion-item menu-close ng-click="login()">
Login
</ion-item>
<ion-item menu-close href="#/app/search">
Search
</ion-item>
<ion-item menu-close href="#/app/browse">
Browse
</ion-item>
<ion-item menu-close href="#/app/playlists">
Playlists
</ion-item>
<!-- :NEW: Added New Home menu item -->
<ion-item menu-close href="#/app/home">
New Home
</ion-item>
</ion-list>
</ion-content>
</ion-side-menu>
</ion-side-menus>
When I run this app, open the menu, and select the New Home menu option the home.html page does not show properly, it is blank. I am sure I must be doing something stupid here.
I found my stupidity!
I had copied a line from the codepen example that wasn't needed and broke my code. Removing the following code from the home.html fixes the problem.
<script id="templates/home.html" type="text/ng-template">

Ionic Navigation Issue

I am trying to develop the navigation i ionic as follows
AppCtrl to Login or Menu
Then from Menu to Products or Orders or back to Login
My app.html like this
<ion-nav-view name="appContent">
</ion-nav-view>
My menu.html like this
<ion-view>
<ion-side-menus enable-menu-with-back-views="false">
<ion-side-menu-content>
<ion-nav-bar class="bar-stable">
<ion-nav-back-button>
</ion-nav-back-button>
<ion-nav-buttons side="left">
<button class="button button-icon button-clear ion-navicon" menu-toggle="left"></button>
</ion-nav-buttons>
</ion-nav-bar>
<ion-nav-view name="menuContent"></ion-nav-view>
</ion-side-menu-content>
<ion-side-menu side="left">
<ion-header-bar class="bar-stable">
<h1 class="title"></h1>
</ion-header-bar>
<ion-content>
<ion-list>
<ion-item nav-clear menu-close href="#/app/products">
Products
</ion-item>
<ion-item nav-clear menu-close href="#/app/orders">
Orders
</ion-item>
<ion-item nav-clear menu-close ng-click="logout()">
Logout
</ion-item>
</ion-list>
</ion-content>
</ion-side-menu>
</ion-side-menus>
</ion-view>
And my state configurations are like this
$stateProvider
.state('app', {
url: "/app",
abstract: true,
templateUrl: "app/views/app.html",
controller: 'AppCtrl'
})
.state('app.login', {
url: "/login",
views: {
'appContent': {
templateUrl: "app/views/login.html",
controller: 'LoginCtrl'
}
}
})
.state('app.menu', {
url: "/menu",
views: {
'appContent': {
templateUrl: "app/views/menu.html",
controller: 'MenuCtrl'
}
}
})
.state('app.products', {
url: "/products",
views: {
'menuContent': {
templateUrl: "app/views/products.html",
controller: 'ProductsCtrl'
}
}
})
.state('app.productdetail', {
url: "/projects/:productid",
views: {
'menuContent': {
templateUrl: "app/views/productdetail.html",
controller: 'ProductDetailCtrl'
}
}
});
In the AppCtrl I'am navigating to Login or Menu.
It navigates to menu.html succefully,
After that when I select the products or orders it is not further navigating.
I noticed the menuContent navigation view is hosted inside the appContent navigation view.
Is ionic supports this kind of hierarchical navigation?
Please find the codepen here code
When using these kind of hierarchical views, we need to specify under which state the view needs to be rendered. Changing the below line of code in your example, will load the Products page properly.
.state('app.products', {
url: "/products",
views: {
'menuContent#app.menu': {
templateUrl: "templates/products.html",
controller: 'ProductsCtrl'
}
}
});
Notice the change in the view name, menuContent#app.menu this would specify the router to render the products view under menu state. Read through more on this in original documentation https://github.com/angular-ui/ui-router/wiki/Multiple-Named-Views

How to ng-hide login button after successful login Ionic?

I have started sideMenu app in ionic and tried some implementation. Initially, ionicModal is used to show login so i change it with ion-list item like;
<ion-side-menu side="left" >
<ion-header-bar class="bar-stable bar-dark">
<a ng-click="redirectToWeb()" > <h1 class="title">NerdApp</h1></a>
</ion-header-bar>
<ion-content >
<ion-list class="BGcolorDG">
<ion-item nav-clear menu-close class="BGcolorDG item item-icon-left item-content-modified" href="#/app/login" ng-show="control.showLogin" > <!--ng-click="login()" -->
<i class="icon ion-locked"></i> <span>Login</span>
</ion-item>
<ion-item nav-clear menu-close href="#/app/search" class="item item-icon-left BGcolorDG item-content-modified">
<i class="icon ion-search"></i><span>Search</span>
</ion-item>
<ion-item nav-clear menu-close href="#/app/browse" class="item item-icon-left BGcolorDG item-content-modified">
<i class="icon ion-ios-browsers"></i><span>Browse</span>
</ion-item>
<ion-item nav-clear menu-close href="#/app/playlists" class="item item-icon-left BGcolorDG item-content-modified">
<i class="icon ion-music-note"></i> <span>Playlists</span>
</ion-item>
</ion-list>
</ion-content>
</ion-side-menu>
and provide routeState as
state('app', {
url: "/app",
abstract: true,
templateUrl: "templates/menu.html",
controller: 'AppCtrl'
})
.state('app.login', {
url: "/login",
views: {
'menuContent': {
templateUrl: "templates/login.html",
controller: "LoginCtrl"
}
}
})
.state('app.home', {
url: "/home",
views: {
'menuContent': {
templateUrl: "templates/home.html",
controller: "HomeCtrl"
}
}
})
And default route to home controller.
$urlRouterProvider.otherwise('/app/home');
the app controller is as
.controller('AppCtrl', function($scope,$timeout,$location,$rootScope) {
$scope.control = {
showLogin:true
};
if($rootScope.showLogin != undefined && $rootScope.showLogin == false){
$scope.control.showLogin = false;
}
})
Inside loginControl i am checking and redirecting it back to home controller as
$scope.login = function() {
if ($scope.loginData.username == 'hassaan' && $scope.loginData.password == 'khan') {
$rootScope.showLogin = false;
// $location.path('#/app');
$state.go('app.home');
}else{
alert('Incorrect credentials');
}
}
i have tried both $location.path and $state.go and what its doing is redirecting to home page but 'not showing the sidemenu' and when i inspect in browser it showing sidemenu hidden.
The flow images of test app is as
Try use $rootScope
pass it to AppCtrl
.controller('AppCtrl', function (...., $rootScope) {
// and then
$rootScope.control = {
showProfile: false
};
after success authentication - make it true
$rootScope.control = {
showProfile: true
};
now it should work as you expected
Don't use $rootscop if you dont need to.
You can send variables to other controllers with the router from angular using params.
.state('menu.employeeInfo', {
url: '/employeeInfo',
views: {
'side-menu21': {
templateUrl: 'templates/employeeInfo.html',
controller: 'employeeInfoCtrl'
}
},
params: {
appointmentObj: null,
subassignmentObj: null
}
})
You can then pass these vars in the following manner.
$scope.gotoAppointment = function (Appointment, Subassignment) {
$state.go('menu.employeeInfo', { appointmentObj: Appointment, subassignmentObj: Subassignment }, { reload: true });
}

Resources