AngularJS ui-sref not working in navbar dropdown Bootstrap on mobile - angularjs

Using UI-Router for Angular and Bootstrap for a navbar I'm trying to turn anchor inside dropdown clickable on but isn't working on mobile. I saw ui-sref not working in bootstrap dropdown and the solution is not working for me. I'm not getting any error on console.
HTML:
<div class="container">
<a class="mainnav-toggle is-open" data-toggle="collapse" data-target=".mainnav-collapse">
<span class="sr-only">Toggle navigation</span>
<i class="fa fa-bars"></i>
</a>
<nav class="mainnav-collapse collapse" role="navigation" aria-expanded="false" style="height: 0px;">
<ul class="mainnav-menu">
<li class="dropdown">
<a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown">
Links<i class="mainnav-caret"></i>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a ui-sref="auth.add()">
<i class="fa fa-users dropdown-icon" aria-hidden="true"></i>
Link 1
</a>
</li>
<li>
<a ui-sref="auth.list()">
<i class="fa fa-history dropdown-icon" aria-hidden="true"></i>
Link 2
</a>
</li>
</ul>
</li>
</ul>
</nav>
</div>
Reference Order:
<script src="bower_components/jquery.slimscroll/jquery.slimscroll.min.js"></script>
<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="bower_components/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js"></script>
<script src="bower_components/bootstrap-datepicker/dist/locales/bootstrap-datepicker.pt-BR.min.js"></script>
<script src="bower_components/select2/dist/js/select2.min.js"></script>
<script src="bower_components/angular/angular.min.js"></script>
<script src="bower_components/angular-animate/angular-animate.min.js"></script>
<script src="bower_components/angular-loading-bar/src/loading-bar.js"></script>
<script src="bower_components/angular-ui-router/release/angular-ui-router.min.js"></script>
<script src="bower_components/angular-local-storage/dist/angular-local-storage.min.js"></script>
<script src="bower_components/angular-messages/angular-messages.min.js"></script>
<script src="bower_components/angular-bootstrap/ui-bootstrap.min.js"></script>
<script src="bower_components/angular-bootstrap/ui-bootstrap-tpls.min.js"></script>
<script src="bower_components/angular-bootstrap-toggle/dist/angular-bootstrap-toggle.min.js"></script>
<script src="dist/app.min.js"></script>
JS: the UI-Router config:
var app = angular.module('accountsMod');
app.config(function routeConfig ($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise("/login");
$stateProvider
.state('auth.add', {
url: '/accounts/add',
controller: 'AccountController',
templateUrl: 'app/components/account/add.html'
})
.state('auth.list', {
url: '/accounts/add',
controller: 'AccountController',
templateUrl: 'app/components/account/list.html'
})
}
The problem focus is: when I touch on these anchors in navbar collapsed according to responsive design provided by bootstrap on mobile phone, then menu closes and nothing happening.

One solution: I had to install 'angular-ui-bootstrap' package and did some changes as follow:
Referencing to directive:
var app = angular.module('accountsMod',['ui.router', 'ui.bootstrap']);
Replacing each html tag for toggle menu as follow (about old in comment):
HTML:
`
Toggle navigation
<nav class="mainnav-collapse collapse" role="navigation" aria-expanded="false" style="height: 0px;">
<ul class="mainnav-menu">
<li uib-dropdown> <!--OLD: <li class="dropdown">-->
<a uib-dropdown-toggle> <!--OLD:<a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown">-->
Links<i class="mainnav-caret"></i>
</a>
<ul uib-dropdown-menu><!--OLD: <ul class="dropdown-menu" role="menu">-->
<li>
<a ui-sref="auth.add()">
<i class="fa fa-users dropdown-icon" aria-hidden="true"></i>
Link 1
</a>
</li>
<li>
<a ui-sref="auth.list()">
<i class="fa fa-history dropdown-icon" aria-hidden="true"></i>
Link 2
</a>
</li>
</ul>
</li>
</ul>
</nav>
`
So the UI-SREF links started working in mobile navigation!! Tks!

Related

Showing menus, based on menuIds using angular js

I am trying to show menus on the homepage(index.html), based on the menuIds.
The menuIds are fetched based on the users role, through a http request to the backend server, when the user logins.
I am setting these menuIds in cookies (login.js)
ng-if directive is used to hide/show specific menus.
Here is the index.html file :
<!DOCTYPE HTML>
<html ng-app="InvoiceApp">
<head>
<title>Invoicing System</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/javascript" src="/vendor/angular-1.2.6/angular.min.js"></script>
<script type="text/javascript" src="/vendor/angular-1.2.6/angular-route.min.js"></script>
<link href='/vendor/bootstrap/css/bootstrap.min.css' rel='stylesheet' />
<script type="text/javascript" src="/vendor/angular-ui/ui-bootstrap-tpls-0.12.0.js"></script>
<script type="text/javascript" src="/vendor/angular-1.2.6/angular-cookies.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript" src="/vendor/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/finance/js/adjustments-controllers.js"></script>
<script type="text/javascript" src="/finance/js/invoice-controllers.js"></script>
<script type="text/javascript" src="/finance/js/finance-services.js"></script>
<link rel="icon" href="/img/favicon.ico" >
<link href='/css/main.css' rel='stylesheet' />
<link href='/css/dashboard.css' rel='stylesheet' />
</head>
<body>
<div class="container-fuild">
<div class="row header">
<div class="col-lg-2">
<img src="/img/rbOutlineLogo.png" height="64px" style = "margin-top:15px; margin-left:20px"/>
</div>
<div class="col-lg-10" style="margin-top:15px">
<img src="/img/cis_logo_new.png" height="64px">
</div>
</div>
<div class="row body">
<div class="col-lg-2" ng-controller="SidebarCtrl">
<div class="nav">
<ul class="nav nav-pills nav-stacked" style="padding-top:7px">
<li class="dropdown navBarStyle" ng-if = "**menuList.indexOf(1) !== -1**">
<a href class="dropdown-toggle" data-toggle="dropdown">
<span class="glyphicon glyphicon-th-list"></span>
View Invoice
<span class="caret"></span>
</a>
<ul class="dropdown-menu nav nav-pills nav-stacked" role="menu">
<li class="navBarStyle">
<a href="#/viewByBOCode">
<span class="glyphicon glyphicon-th">
By BO Code & Date Range
</span>
</a>
</li>
<li class="navBarStyle">
<a href="#/viewByInvoiceNumber">
<span class="glyphicon glyphicon-th">
By Invoice Number
</span>
</a>
</li>
</ul>
</li>
<li class="navBarStyle" ng-if = "**menuList.indexOf(2)** !== -1">
<a href="#/configureBO">
<span class="glyphicon glyphicon-edit"></span>
Configure BO
</a>
</li>
<li class="navBarStyle" ng-if = "**menuList.indexOf(3)** !== -1">
<a href="#/approveBO">
<span class="glyphicon glyphicon-edit"></span>
Configure BO Status
</a>
</li>
<li class="navBarStyle" ng-if = "**menuList.indexOf(4)** !== -1">
<a href class="dropdown-toggle" data-toggle="dropdown">
<span class="glyphicon glyphicon-th-list"></span>
Download Reports
<span class="caret"></span>
</a>
<ul class="dropdown-menu nav nav-pills nav-stacked" role="menu">
<li class="navBarStyle">
<a href="#/generateReport">
<span class="glyphicon glyphicon-download-alt"></span>
Invoice & Transaction History Reports
</a>
</li>
<li class="navBarStyle">
<a href="#/yourBusPendingAdjustmentMemos">
<span class="glyphicon glyphicon-download-alt"></span>
YourBus Pending Adjustment Memos
</a>
</li>
</ul>
</li>
<li class="navBarStyle" ng-if = "menuList.indexOf(5) !== -1">
<a href="#/uploadExcelFile">
<span class="glyphicon glyphicon-upload"></span>
Upload Payment Details
</a>
</li>
<li class="navBarStyle" ng-if = "menuList.indexOf(6) !== -1">
<a href="#/summary/operator/">
<span class="glyphicon glyphicon-th"></span>
Operator Dashboard
</a>
</li>
<li class="navBarStyle" ng-if = "menuList.indexOf(7) !== -1">
<a href="#/adjusmentsMemo">
<span class="glyphicon glyphicon-check"></span>
Create Adjustment Memo
</a>
</li>
<li class="dropdown navBarStyle" ng-if = "menuList.indexOf(8) !== -1">
<a href class="dropdown-toggle" data-toggle="dropdown">
<span class="glyphicon glyphicon-check"></span>
Advance Payment Adjustments
<span class="caret"></span>
</a>
<ul class="dropdown-menu nav nav-pills nav-stacked"
ng-if = "menuList.indexOf(9) !== -1 || menuList.indexOf(10) !== -1 || menuList.indexOf(11) !== -1" role="menu">
<li class="navBarStyle"
ng-if = "menuList.indexOf(9) !== -1">
<a href="#/doAdvancePayment">
<span class="glyphicon glyphicon-edit"></span>
Do Adjustment
</a>
</li>
<li class="navBarStyle" ng-if = "menuList.indexOf(10) !== -1">
<a href="#/approveAdvanceAdjustment">
<span class="glyphicon glyphicon-edit"></span>
Approve Adjustments
</a>
</li>
<li class="navBarStyle"
ng-if = "menuList.indexOf(11) !== -1">
<a href="#/approvedAdvanceAdjustments">
<span class="glyphicon glyphicon-edit"></span>
View Approved Adjustments
</a>
</li>
</ul>
</li>
<li class="dropdown navBarStyle" ng-if = "menuList.indexOf(12) !== -1">
<a href class="dropdown-toggle" data-toggle="dropdown">
<span class="glyphicon glyphicon-check"></span>
Other Adjustments
<span class="caret"></span>
</a>
<ul class="dropdown-menu nav nav-pills nav-stacked"
ng-if = "menuList.indexOf(13) !== -1 || menuList.indexOf(14) !== -1 || menuList.indexOf(15) !== -1 || menuList.indexOf(16) !== -1" role="menu">
<li class="navBarStyle" ng-if = "menuList.indexOf(13) !== -1">
<a href="#/doOtherAdjustments">
<span class="glyphicon glyphicon-edit"></span>
Do Adjustments for Today
</a>
</li>
<li class="navBarStyle" ng-if = "menuList.indexOf(14) !== -1">
<a href="#/viewAdjustments">
<span class="glyphicon glyphicon-edit"></span>
View Adjustments
</a>
</li>
<li class="navBarStyle" ng-if = "menuList.indexOf(15) !== -1">
<a href="#/invoiceAdjustments">
<span class="glyphicon glyphicon-edit"></span>
Approve Adjustments
</a>
</li>
<li class="navBarStyle" ng-if = "menuList.indexOf(16) !== -1">
<a href="#/approvedOtherAdjustments">
<span class="glyphicon glyphicon-edit"></span>
View Approved Adjustments
</a>
</li>
</ul>
</li>
<li ng-if = "menuList.indexOf(17) !== -1" style="background-color: #eee; border-radius:5px">
<a href="#/generateInvoice">
<span class="glyphicon glyphicon-th"></span>
Generate Invoice
</a>
</li>
<li>
<a href="#/logout">
<span class="glyphicon glyphicon-off"></span>
Logout
</a>
</li>
<li>
<a target="_blank" href="https://docs.google.com/document/d/12MMSYpfvCI0A694L5ujOnHziOU71Mhce-iRx99jeFU8/pub?embedded=true">
<span class="glyphicon glyphicon-question-sign"></span>
FAQ
</a>
</li>
</ul>
</div>
</div>
<div class="col-lg-10" style="border-left: 1px solid #F0EDED; min-height:528px">
<div ng-view>This is main page.</div>
</div>
</div>
<div class="row footer" style="padding:10px">
<span class="glyphicon glyphicon-copyright-mark"></span>
<script>document.write(new Date().getFullYear())</script> ibibogroup All rights reserved
</div>
</div>
</body>
</html>
Here is the login.js logic to fetch the menuIds based on the user :
var url = '/api/user/login/ui';
$http.post(url, {
userName: $scope.credential.email,
password: $scope.credential.password
}).success(function(data, status, headers, config) {
**$cookies.menuList = data;
$window.location.href = 'index.html';**
}).error(function(data, status, headers, config) {
if (status === 400) {
$scope.errors.push("Invalid Credential, please try again.");
} else {
$scope.errors.push("Service not available currently, please try again after some time.");
}
});
Here is the controller for the index.html
angular.module('**InvoiceControllers**', ['ngCookies'])
.controller('**SidebarCtrl**', function($scope, $cookies, $log, $window) {
**$scope.menuList = [];
$scope.menuList = $cookies.permissions;**
$log.info($scope.menuList);
if (angular.isUndefined($scope.menuList)) {
$window.location.href = 'login.html';
}
});
But upon loading the index.html,
the snippet -> ng-if = "menuList.indexOf(menu_id) !== -1"
is not working.
What i am doing woring here?
You can use by this way
data-ng-if = "menuList.map(function(x) {return x.id; }).indexOf(menu_id) != -1"
But better thing if you use method
data-ng-if = "getMenuStatus(menu_id)"
$scope.getMenuStatus = function(menu_id)
{
return menuList.map(function(x) {return x.id; }).indexOf(menu_id) !== -1;
}
I think it will work

UI-Router 1.0.0-beta.2 and UI-Bootstrap 2.1.4 dropdown not closing

I'm using ui-route ui-sref in my links with the navbar using UI-Bootstrap dropdowns and if I use the anchor tag with href, the dropdown closes on click, but the anchor tags with ui-sref does not close the dropdown. I've got the following plnkr with it showing the bug.
Angular Code
angular.module('app', ['ui.bootstrap', 'ui.router'])
.config(appRoute)
.controller('myController', myController);
appRoute.$inject = ['$stateProvider'];
function appRoute($stateProvider) {
$stateProvider.state('index', {
url: '/index',
template: '<h1>indexRoute</h1>'
})
.state('other', {
url: '/other',
template: '<h1>otherRoute</h1>'
})
}
function myController() {
var ctrl = this;
ctrl.title = 'Title';
ctrl.user = 'User#user.com';
ctrl.test = test;
ctrl.test2 = test2;
function test() {
console.log('TEST LINK!')
}
function test2() {
console.log('TEST 2')
}
}
HTML
<body ng-controller="myController as $ctrl" style="{padding-top: 70px;}">
<nav id="isec-menu" class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<div class="intelisecure-header">
<span>{{$ctrl.title}}</span>
</div>
</div>
<div class="collapse navbar-collapse navbar-right">
<ul class="nav navbar-nav">
<li id="usermenu" class="dropdown user-menu-dropdown" uib-dropdown="">
<a href="" class="uib-dropdown-toggle username" uib-dropdown-toggle="">
<i class="fa fa-user fa-fw"></i>
{{$ctrl.user}} <span class="caret"></span>
</a>
<ul class="dropdown-menu" uib-dropdown-menu="" role="menu">
<li role="menuitem">
<a href="/index" ng-click="$ctrl.test()">
<i class="fa fa-fw fa-sign-out menu-icon"></i>
<span class="menu-text">index href</span>
</a>
</li>
<li role="menuitem">
<a ui-sref="other" ng-click="$ctrl.test2()">
<i class="fa fa-fw fa-sign-out menu-icon"></i>
<span class="menu-text">other sref</span>
</a>
</li>
<li role="menuitem">
<a href="" ng-click="$ctrl.logout()">
<i class="fa fa-fw fa-sign-out menu-icon"></i>
<span class="menu-text">Logout</span>
</a>
</li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
<ui-view>
<div>
test
</div>
</ui-view>
</body>
Not perfectly built, I was trying to see if I could replicate the issue with my
https://plnkr.co/edit/Rz3AbgnYnWI34DjuByY6?p=preview
Apparently this was a known issue and was resolved by updating to UI-Router 1.0.0-beta.3

UI routing not working, angular JS

I'm trying to display main.html template via UI routing, but its not working for some reason. Can someone please point out the mistake in my code. Thank you.
appModule
"use strict";
angular.module("fleetOperate", ["ui.router", "mainModule"]);
UI Routing
"use strict";
angular.module('fleetOperate').config(function ($stateProvider) {
$stateProvider
.state('main', {
url: '/main',
templateUrl: 'app/main/main.html'
})
});
mainModule
"use strict";
angular.module("mainModule", []);
main.HTML
<div class="icon-bar" ui-view="main">
<a ui-sref="" class="item">
<i class="fa fa-truck" style="font-size:48px;"></i>
<label>Fleet</label>
</a>
<a ui-sref="" class="item">
<i class="fa fa-users" style="font-size:48px;"></i>
<label>Drivers</label>
</a>
<a href="#" class="item">
<i class="fa fa-calendar" style="font-size:48px;"></i>
<label>Planner</label>
</a>
<a href="#" class="item">
<i class="fa fa-truck" style="font-size:48px;"></i>
<label>Trailors</label>
</a>
<a href="#" class="item">
<i class="fa fa-files-o" style="font-size:48px;"></i>
<label>Pod</label>
</a>
<a href="#" class="item">
<i class="fa fa-cog" style="font-size:48px;"></i>
<label>Settings</label>
</a>
<a href="#" class="item">
<i class="fa fa-square-o" style="font-size:48px;"></i>
<label>Control Center</label>
</a>
<a href="#" class="item">
<i class="fa fa-phone" style="font-size:48px;"></i>
<label>Communication</label>
</a>
<a href="#" class="item">
<i class="fa fa-user" style="font-size:48px;"></i>
<label>Customer Profile</label>
</a>
</div>
Index.HTML
<!DOCTYPE html>
<html ng-app="fleetOperate">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title>Truck Trackers</title>
<link href="Content/bootstrap.min.css" rel="stylesheet" />
<link href="Content/font-awesome.min.css" rel="stylesheet" />
<link href="app/app.css" rel="stylesheet" />
<link href="app/main/main.css" rel="stylesheet" />
<script src="scripts/angular.js"></script>
<script src="scripts/jquery-2.1.4.min.js"></script>
<script src="scripts/angular-ui-router.min.js"></script>
<script src="app/main/mainModule.js"></script>
<script src="app/appModule.js"></script>
<script src="app/appUI_Routing.js"></script>
</head>
<body class="container-fluid">
<header class="js-title-bar">
<div class="js-logo-area">
<img class="js-icon" ng-src="http://www.cam-trucks.com/images/2.jpg"/>
<div class="js-title-area">
<p class="js-logo-title"> <strong>Truck Tracker's</strong></p>
<p class="js-logo-subtitle">Where ever you GO, we FIND you !</p>
</div>
</div>
</header>
<div ui-view></div>
</body>
</html>
Update your UI Router:
angular.module('fleetOperate').config(function ($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise("main");
$stateProvider
.state('main', {
url: '/main',
templateUrl: 'app/main/main.html'
})
});

Bootstrap Dropdown is not working

I've added the dropdown in the header.html which i included in the index.html of an angular app.
<ul class="nav navbar-nav navbar-right">
<li class="dropdown profile hidden-xs">
<a class="dropdown-toggle" data-toggle="dropdown">
<span class="meta">
<span class="text">{{slUserObj.username}}</span>
<span class="caret"></span>
</span>
</a>
<ul class="dropdown-menu animated flipInX" role="menu">
<li>
<a href="javascript:void(0);" ng-click="showProfile();main.page='profile'">
<span class="icon"><i class="fa fa-user"></i>
</span>My Account</a>
</li>
<li>
<a href="javascript:void(0);" ng-click="showProfile();main.page='profile'">
<span class="icon"><i class="fa fa-user"></i>
</span>Carreir Details</a>
</li>
<!--<li>
<a href="javascript:void(0);">
<span class="icon"><i class="fa fa-envelope"></i>
</span>Messages</a>
</li>
<li>
<a href="javascript:void(0);">
<span class="icon"><i class="fa fa-cog"></i>
</span>Settings</a>
</li>-->
<li class="divider"></li>
<li>
<a href="javascript:void(0);" ng-click="logout()">
<span class="icon"><i class="fa fa-sign-out"></i>
</span>Logout</a>
</li>
</ul>
</li>
here is the index.html
<section id="main-wrapper" class="theme-default">
<!-- Page wrapper -->
<header id="header" ng-include="'views/header.html'" ng-show="isAuthenticated"></header>
<!-- Left Sidebar Navigation -->
<aside class="sidebar sidebar-left" ng-include="'views/left-sidebar.html'" ng-show="isAuthenticated"></aside>
<!-- Content wraper -->
<section class="main-content-wrapper" ng-class="{'main-content-wrapper':isAuthenticated,'main-content-wrapper-full':!isAuthenticated}">
<!-- Main content view -->
<div ui-view></div>
<!-- Footer -->
<div ng-include="'views/footer.html'"></div>
</section>
<!-- /Content wraper-->
Now the dropdown in the header.html is not working once unhiding the header block after login, but its working when i'm refreshing the page after login.

Integrating AngularJS contact form in a bootstrap designed page - Navbar's dropdowns not working

I created a contact form with angularJS and when I try to integrate it in the page that I built with bootstrap, the Navbar dropdowns and the toggle button don't work. How do I fix it in the best and easiest way?
Link To My Code
<div class="navbar navbar-inverse navbar-static-top" role="navigation">
<div class="container">
<button class="navbar-toggle" data-toggle="collapse" data-target=".navHeaderCollapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div class="collapse navbar-collapse navHeaderCollapse">
<ul class="nav navbar-nav navbar-right">
<li><span class="glyphicon glyphicon-home"></span> Home</li>
<li class="dropdown">
<span class="glyphicon glyphicon-briefcase"></span> Our Product<b class="caret"></b>
<ul class="dropdown-menu">
<li>A Collaborative Solution </li>
<li>A Robust Platform</li>
<li>How It Works</li>
</ul
</li>
<li class="dropdown">
<span class="glyphicon glyphicon-user"></span> About Us<b class="caret"></b>
<ul class="dropdown-menu">
<li>Our Team</li>
<li>Our Advisory Board</li>
<li>Our Partners</li>
<li>Our Customers</li>
</ul>
</li>
<li class="dropdown">
<span class="glyphicon glyphicon-list-alt"></span> In the News<b class="caret"></b>
<ul class="dropdown-menu">
<li>Press Releases</li>
<li>Industry News</li>
</ul>
</li>
<li class="active"><span class="glyphicon glyphicon-envelope"></span> Contact Us </li>
</ul>
</div>
</div>
</div>
Thanks for the help!
Don't use Bootstrap's js file and try to avoid jQuery with Angular (jQuery shouldn't be needed). Instead, just include UI Bootstrap and it will add bootstrap's JavaScript functionality as Angular directives.
Include the ui-bootstrap script:
<script src="//cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.10.0/ui-bootstrap-tpls.min.js"></script>
then, inject it as a module dependency in your app:
angular.module('myApp', [
'ui.bootstrap'
]);
This will make the Bootstrap components work in your application. Be sure to read the documentation for UI Bootstrap.

Resources