Last active
August 29, 2015 14:02
-
-
Save cpoDesign/9ea86f5ea8b382c06f2b to your computer and use it in GitHub Desktop.
Implementing breadcrumbs into site with AngularJS v1.2.16. Implementation uses breadcrumb module by Ian Kennington Walter (http://ianvonwalter.com)
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
var app = angular.module('app', ['ngRoute','ng-breadcrumbs']); | |
app.config(function($routeProvider) { | |
$routeProvider.when('/', | |
{ | |
templateUrl: 'templates/list.html', | |
controller: 'listCtr', | |
label:'Administration' | |
}) | |
.when('/detail/', | |
{ | |
templateUrl: 'templates/detail.html', | |
controller: 'detailCtr', | |
label: 'Detail' | |
}) | |
.otherwise({ redirectTo: '/' }); | |
}); | |
// controller definition | |
app.controller('listCtr', | |
function priorityCtr($scope, $location){ | |
$scope.items = [ | |
{name: 'test', id: '1'}, | |
{name: 'test 3', id: '3'}, | |
{name: 'test 2', id: '2'}, | |
]; | |
$scope.openDetail = function(){ | |
$location.url('/detail/'); | |
} | |
}) | |
.controller('detailCtr', | |
function priorityCtr($scope){ | |
}) | |
.controller('HomeController', | |
function($scope, breadcrumbs) { | |
$scope.breadcrumbs = breadcrumbs; | |
}); |
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
<h2>Detail</h2> |
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 ng-app="app"> | |
<head> | |
<script src="../js/angular.js" type="application/javascript"></script> | |
<script src="../js/angular-route.js" type="application/javascript"></script> | |
<script src="ng-breadcrumbs.js"></script> | |
<script src="app.js"></script> | |
</head> | |
<body ng-controller="HomeController"> | |
<div id="breadcrumbs"> | |
<ol> | |
<li ng-repeat="breadcrumb in breadcrumbs.get() track by breadcrumb.path" ng-class="{ active: $last }"> | |
<a ng-if="!$last" ng-href="#{{ breadcrumb.path }}" ng-bind="breadcrumb.label" class="margin-right-xs"></a> | |
<span ng-if="$last" ng-bind="breadcrumb.label"></span> | |
</li> | |
</ol> | |
</div> | |
<div style="clear: both"> | |
<ng-view ></ng-view> | |
</div> | |
</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
<h2>list of all items</h2> | |
<div ng-repeat="item in items"> | |
<h2>{{item.name}}</h2> | |
<p><button ng-click="openDetail()">detail</button></p> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment