Created
November 10, 2016 17:09
-
-
Save hk-skit/8ae3c4b181c9e457cb4d50be23e8c0cd to your computer and use it in GitHub Desktop.
Hello World with UI-Router
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<title>Hello ui-router</title> | |
<link rel="stylesheet" href="style.css"> | |
</head> | |
<body ng-app="HelloWorld"> | |
<header> | |
<nav> | |
<ul> | |
<li><a ui-sref="home" ui-sref-active="active">Home</a></li> | |
<li><a ui-sref="about" ui-sref-active="active">About</a></li> | |
<li><a ui-sref="contact" ui-sref-active="active">Contact</a></li> | |
<li><a ui-sref="other" ui-sref-active="active">Other</a></li> | |
</ul> | |
</nav> | |
</header> | |
<section> | |
<ui-view></ui-view> | |
</section> | |
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script> | |
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.3.2/angular-ui-router.min.js"></script> | |
<script type="text/javascript" src="script.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
'use strict'; | |
var app = angular.module('HelloWorld', ['ui.router']); | |
app.config(['$urlRouterProvider','$stateProvider', function($urlRouterProvider, $stateProvider){ | |
[ | |
'home', | |
'about', | |
'contact', | |
'other' | |
].forEach(state => $stateProvider.state(state, { | |
url: `/${state}`, | |
template: `<h1>This is ${state} page.</h1>` | |
})); | |
//If anything is wrong go to home page. | |
$urlRouterProvider.otherwise('/home'); | |
}]); | |
}()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body{ | |
background: #EAEAEA; | |
margin: 0; | |
padding: 0; | |
} | |
a{ | |
color: white; | |
text-decoration: none; | |
} | |
a:hover{ | |
color: tomato; | |
} | |
.active{ | |
color: teal; | |
} | |
header{ | |
background: #333; | |
padding: 10px; | |
text-align: center; | |
} | |
header ul{ | |
margin: 0; | |
padding: 0; | |
} | |
header li{ | |
display: inline-block; | |
margin: 0 15px; | |
} | |
header li{ | |
font-size: 1.5em; | |
font-weight: bold; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment