I am currently honing my skills in Angular JS
routing. After successfully implementing 2 pages routing, I now aim to achieve 3 pages routing.
(function() {
'use strict';
angular
.module('testTabs', ['ngMaterial', 'ui.router', 'ngAnimate'])
.config(function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/one');
$stateProvider
.state('one', {
url: '/one',
templateUrl: 'views/one.html'
})
.state('two', {
url: '/two',
templateUrl: 'views/two.html'
})
.state('three', {
url: '/three',
templateUrl: 'views/three.html'
});
})
})();
#tab-container {
position: relative;
min-height: 500px;
overflow: hidden;
}
#tab-content {
background: #f6f6f6;
border: 1px solid #e1e1e1;
min-height: 200px;
width: 100%;
}
/* basic animation applied upon partial change */
#tab-content.ng-enter,
#tab-content.ng-leave {
position: absolute;
transition: 0.8s all ease;
-moz-transition: 0.8s all ease;
-webkit-transition: 0.8s all ease;
}
#tab-content.ng-enter {
-webkit-animation: slideRight 0.8s both ease;
-moz-animation: slideRight 0.8s both ease;
animation: slideRight 0.8s both ease;
}
#tab-content.ng-leave {
-webkit-animation: slideLeft 0.8s both ease;
-moz-animation: slideLeft 0.8s both ease;
animation: slideLeft 0.8s both ease;
}
/*Animations */
@keyframes slideLeft {
to {
transform: translateX(-200%);
}
}
@-moz-keyframes slideLeft {
to {
-moz-transform: translateX(-200%);
}
}
@-webkit-keyframes slideLeft {
to {
-webkit-transform: translateX(-200%);
}
}
@keyframes slideRight {
from {
transform: translateX(200%);
}
to {
transform: translateX(0);
}
}
@-moz-keyframes slideRight {
from {
-moz-transform: translateX(200%);
}
to {
-moz-transform: translateX(0);
}
}
@-webkit-keyframes slideRight {
from {
-webkit-transform: translateX(200%);
}
to {
-webkit-transform: translateX(0);
}
}
<!DOCTYPE html>
<html>
<head>
<title>PG Application</title>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/angular-material/1.0.7/angular-material.min.css">
<link rel="stylesheet" type="text/css" href="style.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-animate.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-aria.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-material/1.0.7/angular-material.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.18/angular-ui-router.min.js"></script>
<script src="app.js"></script>
</head>
<body>
<div ng-cloak="" ng-app="testTabs">
<script type="text/ng-template" id="views/one.html">
<h1 class="md-display-1">Partial 1</h1>
</script>
<script type="text/ng-template" id="views/two.html">
<h1 class="md-display-1">Partial 2</h1> </script>
<script type="text/ng-template" id="views/three.html">
<h1 class="md-display-1">Partial 3</h1> </script>
<md-content id="tab-container" class="">
<md-tabs md-dynamic-height="" md-border-bottom="">
<md-tab label="Tab 1" data-ui-sref="one" md-active="true">
</md-tab>
<md-tab label="Tab 2" data-ui-sref="two">
</md-tab>
<md-tab label="Tab 3" data-ui-sref="three">
</md-tab>
</md-tabs>
<md-content id="tab-content" class="md-padding" data-ui-view flex> </md-content>
</md-content>
</div>
</body>
</html>
The above code is functioning correctly.
Issue: When clicking on partial 1
, it should redirect and display the table data.
Now, I would like to link the following code to Partial 1
. So that when clicked, it will display the table data as shown below.
var app=angular.module('myApp',[]);
app.controller('basicsCtrl', ['$scope', function ($scope) {
$scope.rowCollection = [
{firstName: 'Laurent', lastName: 'Renard', birthDate: new Date('1987-05-21'), email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d7a0bfb6a3b2a1b2a597b0bab6bebbf9b4b8ba">[email protected]</a>'},
{firstName: 'Blandine', lastName: 'Faivre', birthDate: new Date('1987-04-25'), email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="91fee4f7f3fdf0fff5fee4d1f6fcf0f8fdbff2fefc">[email protected]</a>'},
{firstName: 'Francoise', lastName: 'Frere', birthDate: new Date('1955-08-27'), email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6b190a120604050f0e0d2b0c060a020745080406">[email protected]</a>'}
];
}]);
<!DOCTYPE html>
<html>
<head>
<title>Table</title>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.5/angular.min.js"></script>
<script src="tapp.js"></script>
</head>
<body ng-app="myApp" ng-controller="basicsCtrl">
<table class="table table-striped">
<thead>
<tr>
<th>first name</th>
<th>last name</th>
<th>birth date</th>
<th>balance</th>
<th>email</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="row in rowCollection">
<td>{{row.firstName}}</td>
<td>{{row.lastName}}</td>
<td>{{row.birthDate}}</td>
<td>{{row.balance}}</td>
<td>{{row.email}}</td>
</tr>
</tbody>
</table>
</body>
</html>