Ui-Routing For Nested States & Nested Views

 

index.html

<html ng-app="main">
<head>
<script src="https://code.angularjs.org/1.6.0-rc.2/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.3.2/angular-ui-router.min.js"></script>
<script type="text/javascript" src="custom.js">
</script>
</head>
<body>
<h1>Home</h1><br/>
    <a ui-sref="about">About</a>    
 

<div class="container" ui-view></div>


</body>
</html>


app.js

var app = angular.module('main', ['ui.router']);

 app.config(['$stateProvider',function($stateProvider) {
          $stateProvider.
state('about', {
  url: '',
views: {
'': { templateUrl: 'pages/about.html' },
'services@about': { templateUrl: 'pages/services.html' },
'account@about': { templateUrl: 'pages/account.html' }
}
});
}])

about.html

<!--concept of nested views -->
<a ui-sref="home">Back</a>    
<div ui-view="services"></div>
<div ui-view="account"></div>









Previous
Next Post »