My website has a top-level menu and left menus that are updated based on the selected top-level menu. When I click on a left menu item, it resets and becomes blank, as shown when clicking on HOME
. Currently, only HOME
is connected, while Route1
and Route2
are not.
For reference, you can view the Plunker example here: http://plnkr.co/edit/Jwow4VtNsSfMMcpv6qaa?p=preview
How can I prevent the left menu from resetting/reloading on selection? I also want to maintain the highlight on the clicked left menu item.
<!DOCTYPE html>
<html ng-app="myapp">
<head>
<title>AngularJS: UI-Router Quick Start</title>
<!-- Bootstrap CSS -->
<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.1/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="container">
<div class="navbar">
<div class="navbar-inner">
<a class="brand" ui-sref="index">Quick Start</a>
<ul class="nav">
<li><a ui-sref="index">Home</a></li>
<li><a ui-sref="route1">Route 1</a></li>
<li><a ui-sref="route2">Route 2</a></li>
</ul>
</div>
</div>
<div class="row">
<div class="span6">
<div class="well" ui-view="LeftMenu"></div>
</div>
<div class="span6">
<div class="well" ui-view="Content"></div>
</div>
</div>
<!-- Angular -->
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.4/angular.min.js"></script>
<!-- UI-Router -->
<script src="//angular-ui.github.io/ui-router/release/angular-ui-router.js"></script>
<!-- App Script -->
<script>
var myapp = angular.module('myapp', ["ui.router"])
myapp.config(function($stateProvider){
$stateProvider
.state('index', {
url: "",
views: {
"LeftMenu": {
template: '<ul><li><a ui-sref="LeftMenuMenu1">Index-Left Menu1</a></li><li><a ui-sref="LeftMenuMenu2">Index-Left Menu2</a></li><li><a ui-sref="LeftMenuMenu3">Index-Left Menu3</a></li></ul>'
},
"Content": {
template: "LeftMenu index selected"
}
}
})
.state('LeftMenuMenu1', {
views:{
"Content": {
template: "LeftMenu.Menu1 selected"
}
}
})
.state('LeftMenuMenu2', {
views: {
"Content": {
template: "LeftMenu.Menu2 selected"
}
}
})
.state('LeftMenuMenu3', {
url: "",
views: {
"Content": {
template: "LeftMenu.Menu3 selected"
}
}
})
.state('route1', {
url: "/route1",
views: {
"LeftMenu": {
template: '<ul><li><a ui-sref="Route1.Menu1">Route1-Left Menu1</a></li><li><a ui-sref="Route1.Menu2">Route1-Left Menu2</a></li><li><a ui-sref="Route1.Menu3">Route1-Left Menu3</a></li></ul>'
},
"viewB": {
template: "route1.viewB"
}
}
})
.state('route2', {
url: "/route2",
views: {
"LeftMenu": {
template:'<ul><li><a href="">Route2-Left Menu1</a></li><li><a href="">Route2-Left Menu2</a></li><li><a href="">Route2-Left Menu3</a></li></ul>'
},
"viewB": {
template: "route2.viewB"
}
}
})
});
</script>
</body>
</html>