<code><!DOCTYPE html>
<html lang=
"en"
ng-app=
"testApp"
>
<head>
<meta charset=
"UTF-8"
>
<meta http-equiv=
"Content-Type"
content=
"text/html; charset=utf-8"
/>
<meta http-equiv=
"X-UA-Compatible"
content=
"IE=edge,chrome=1"
/>
<title>Title</title>
<script type=
"text/javascript"
src=
"bower_components/jquery/dist/jquery.min.js"
></script>
<script type=
"text/javascript"
src=
"bower_components/angular/angular.min.js"
></script>
<script type=
"text/javascript"
src=
"bower_components/angular-ui-router/release/angular-ui-router.min.js"
></script>
</head>
<body>
<p ui-view></p>
<script type=
"text/javascript"
>
var
testApp = angular.module(
'testApp'
, [
'ui.router'
]);
testApp.config(
function
(
$stateProvider
,
$urlRouterProvider
){
$urlRouterProvider
.otherwise(
'/'
);
$stateProvider
.state(
'index'
, {
url:
'/'
,
template:
'<ul><li ng-repeat="item in items" data-id="{{item.id}}">{{item.name}}</li></ul>'
,
controller:
function
(
$scope
,
$state
){
$scope
.items = [
{
name:
'张三'
,
id: 1
},
{
name:
'李四'
,
id: 2
},
{
name:
'王五'
,
id: 3
}
];
$(
function
(){
$(
'li'
).click(
function
(){
console.info($(this).data(
'id'
));
var
id = $(this).data(
'id'
);
$state
.go(
'index.detail'
, {
id: id
});
});
})
}
})
.state(
'index.detail'
, {
url:
':id'
,
template:
'<h1>This is detail</h1>'
})
});
</script>
</body>
</html></code>