Skip to content

Commit 8a6f2ee

Browse files
committed
Merge pull request #348 from angular-ui/update-sample
More comments in the html files
2 parents 6fd078d + b402e9f commit 8a6f2ee

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

sample/contacts.detail.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
<h2>{{contact.name}}</h2>
33
<ul>
44
<li ng-repeat="item in contact.items">
5-
<a ui-sref="contacts.detail.item({contactId:contact.id, itemId:item.id})">{{item.type}}</a>
5+
6+
<!-- Here's another ui-sref except THIS time we are passing parameters
7+
AND inheriting parameters from active ancestor states. So we don't
8+
need to resupply the contactId parameter. -->
9+
<a ui-sref="contacts.detail.item({itemId:item.id})">{{item.type}}</a>
610
</li>
711
</ul>
812
<div ui-view ng-animate="{enter:'fade-enter'}">

sample/contacts.html

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,24 @@
44
<ul class="nav nav-list">
55
<li ng-class="{ active: $state.includes('contacts.list') }"><a ui-sref="contacts.list">All Contacts</a></li>
66
<li class="nav-header">Top Contacts</li>
7+
8+
<!-- This <li> will only add the 'active' class if 'contacts.detail' or its descendants are active
9+
AND if it is the link for the active contact (aka contactId) -->
710
<li ng-repeat="contact in contacts | limitTo:2"
811
ng-class="{ active: $state.includes('contacts.detail') && $stateParams.contactId == contact.id }">
12+
13+
<!-- Here's a ui-sref that is also providing necessary parameters -->
914
<a ui-sref="contacts.detail({contactId:contact.id})">{{contact.name}}</a>
1015
</li>
1116
</ul>
1217
<hr>
1318
<button class="btn" ng-click="goToRandom()">Show random contact</button>
19+
20+
<!-- Another named view -->
1421
<div ui-view="menuTip"></div>
1522
</div>
1623
</div>
17-
<div class="span9" ui-view ng-animate="{enter:'fade-enter'}"></div>
24+
25+
<!-- Our unnamed main ui-view for this template -->
26+
<div ui-view class="span9" ng-animate="{enter:'fade-enter'}"></div>
1827
</div>

sample/index.html

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
<!doctype html>
2+
<!-- Our uiRouterSample module defined here -->
23
<html lang="en" ng-app="uiRouterSample">
34
<head>
45
<meta charset="utf-8">
56

7+
<!-- using twitter bootstrap, but of course -->
68
<link rel="stylesheet" type="text/css" href="bootstrap.min.css">
9+
<!-- styles for ng-animate are located here -->
710
<link rel="stylesheet" type="text/css" href="styles.css">
811

12+
<!-- Include both angular.js and angular-ui-router.js-->
913
<script src="../lib/angular-1.1.4.js"></script>
1014
<script src="../build/angular-ui-router.js"></script>
15+
16+
<!-- module.js declares the uiRouterSample module and adds items to $rootScope-->
1117
<script src="module.js"></script>
18+
<!-- factory.js defines a 'contacts' http service and a 'utils' global functions service -->
1219
<script src="factory.js"></script>
20+
<!-- state.js takes care of all the state configuration, where all the magic's at-->
1321
<script src="states.js"></script>
1422

1523
<!-- could easily use a custom property of the state here instead of 'name' -->
@@ -18,17 +26,36 @@
1826
<body>
1927
<div class="navbar navbar-fixed-top">
2028
<div class="navbar-inner"><div class="container">
29+
30+
<!-- ui-sref is a great directive for linking a state location with an anchor link.
31+
You should almost always use ui-sref instead of href on your links when you want
32+
then to navigate to a state. When this link is clicked it will take the application
33+
to the 'home' state. Behind the scenes the directive also adds the correct href attr
34+
and url. -->
2135
<a class="brand" ui-sref="home">ui-router</a>
2236
<ul class="nav">
37+
38+
<!-- Here you can see ui-sref in action again. Also notice the use of $state.includes, which
39+
will set the links to 'active' if, for example on the first link, 'contacts' or any of
40+
its descendant states are activated. -->
2341
<li ng-class="{ active: $state.includes('contacts') }"><a ui-sref="contacts.list">Contacts</a></li>
2442
<li ng-class="{ active: $state.includes('about') }"><a ui-sref="about">About</a></li>
2543
</ul>
26-
<p class="navbar-text pull-right" ui-view="hint"></p>
44+
45+
<!-- Here is a named ui-view. ui-views don't have to be named, but we'll be populate this
46+
on from various different child states and we want a name to help us target. -->
47+
<p ui-view="hint" class="navbar-text pull-right"></p>
2748
</div></div>
2849
</div>
29-
<div class="container" style="margin-top:60px" ui-view ng-animate="{enter:'fade-enter'}"></div>
50+
51+
<!-- Here is the main ui-view (unnamed) and will be populate by its immediate children's templates
52+
unless otherwise explicitly named views are targeted. It's also employing ng-animate. -->
53+
<div ui-view class="container" style="margin-top:60px" ng-animate="{enter:'fade-enter'}"></div>
54+
55+
3056
<hr>
3157
<pre>
58+
<!-- Here's some values to keep an eye on in the sample in order to understand $state and $stateParams -->
3259
$state = {{$state.current.name}}
3360
$stateParams = {{$stateParams}}
3461
$state full url = {{ $state.$current.url.source }}

0 commit comments

Comments
 (0)