Created
August 27, 2014 11:49
-
-
Save rosterloh/85356293f7e989b4a6ca to your computer and use it in GitHub Desktop.
Deep linking a tabbed UI
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(){ | |
var app = angular.module("routedTabs", ["ui.router", "ui.bootstrap"]); | |
app.config(function($stateProvider, $urlRouterProvider){ | |
$urlRouterProvider.otherwise("/main/tab1"); | |
$stateProvider | |
.state("main", { abtract: true, url:"/main", templateUrl:"main.html" }) | |
.state("main.tab1", { url: "/tab1", templateUrl: "tab1.html" }) | |
.state("main.tab2", { url: "/tab2", templateUrl: "tab2.html" }) | |
.state("main.tab3", { url: "/tab3", templateUrl: "tab3.html" }); | |
}); | |
app.controller("mainController", function($rootScope, $scope, $state) { | |
$scope.go = function(route){ | |
$state.go(route); | |
}; | |
$scope.active = function(route){ | |
return $state.is(route); | |
}; | |
$scope.tabs = [ | |
{ heading: "Tab 1", route:"main.tab1", active:false }, | |
{ heading: "Tab 2", route:"main.tab2", active:false }, | |
{ heading: "Tab 3", route:"main.tab3", active:false }, | |
]; | |
$scope.$on("$stateChangeSuccess", function() { | |
$scope.tabs.forEach(function(tab) { | |
tab.active = $scope.active(tab.route); | |
}); | |
}); | |
}); | |
}()); |
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> | |
<head></head> | |
<body ng-app="routedTabs" class="container"> | |
<div ui-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
<div ng-controller="mainController"> | |
<tabset> | |
<tab | |
ng-repeat="t in tabs" | |
heading="{{t.heading}}" | |
select="go(t.route)" | |
active="t.active"> | |
</tab> | |
</tabset> | |
<h2>View:</h2> | |
<div ui-view></div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment