<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>AngularJS Plunker</title>
<script>document.write('<base href="' + document.location + '" />');</script>
<link rel="stylesheet" href="style.css" />
<script data-require="angular.js@1.4.x" src="https://code.angularjs.org/1.5.6/angular.min.js" data-semver="1.5.6"></script>
<script data-require="ui-router@*" data-semver="1.0.0-alpha.5" src="//cdnjs.cloudflare.com/ajax/libs/angular-ui-router/1.0.0-alpha.5/angular-ui-router.js"></script>
<script src="app.js"></script>
<script src="home/home.controller.js"></script>
<script src="about/about.controller.js"></script>
<script src="shared/message.component.js"></script>
</head>
<body ng-app="plunker">
<div class="navbar">
<a href="#home">Home</a>
<a href="#about">About</a>
</div>
<div ui-view></div>
</body>
</html>
/* Put your css in here */
.navbar {
width: 100%;
padding-bottom: 5px;
border-bottom: 1px solid;
}
angular.module('plunker', [
'ui.router'
])
.config(function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise("/");
//
// Now set up the states
$stateProvider
.state('home', {
url: "/",
template: "<home></home>"
})
.state('about', {
url: "/about",
template: "<about></about>"
})
}
);
<h1>Home</h1>
<message from="'Home'" msg="$ctrl.message"></message>
<h1>About</h1>
<message from="'About'" msg="$ctrl.message"></message>
angular.module('plunker')
.component('about', {
restrict: 'E',
scope: {},
templateUrl: 'about/about.html',
controller: AboutController
});
function AboutController() {
var vm = this;
vm.message = 'Hi from about';
};
angular.module('plunker')
.component('home', {
restrict: 'E',
scope: {},
templateUrl: 'home/home.html',
controller: HomeController
});
function HomeController() {
var vm = this;
vm.message = 'Hi from home';
};
angular.module('plunker')
.component('message', {
bindings: {
from: '<',
msg: '<'
},
controller: MessageController,
template: [
'<p><strong>A message from {{ $ctrl.from }}:</strong></p>',
'<p>{{ $ctrl.msg }}</p>'
].join('')
});
function MessageController() {}