<script type="text/javascript" src="JS/angular.min.js"></script> <script type="text/javascript" src="JS/angular-ui-router.min.js"></script>
var app = angular.module('myApp', ['ui.router']);
<div ui-view></div>
app.config(["$stateProvider", function ($stateProvider){
$stateProvider
.state("home", { //导航用的名字,如<a ui-sref="login">login</a>里的login
url: '/', //访问路径
template:'<div>模板内容......</div>'
})
}]);
<html>
<head>
<title>ui-router</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!-- 导入JS -->
<script type="text/javascript" src="JS/angular.min.js"></script>
<script type="text/javascript" src="JS/angular-ui-router.min.js"></script>
</head>
<body >
<div ng-app="myApp">
<div ui-view></div> <!-- 视图 -->
</div>
</body>
<script type="text/javascript">
//定义模板,并注入ui-router
var app = angular.module('myApp', ['ui.router']);
//对服务进行参数初始化,这里配stateProvider服务的视图控制
app.config(["$stateProvider", function ($stateProvider) {
$stateProvider
.state("home", {
url: '/',
template:'<div>模板内容......</div>'
})
}]);
</script>
</html>
<body >
<div ng-app="myApp" >
<a ui-sref="parent">点我显示父view内容</a>
<a ui-sref="parent.child">点我显示父view与子view内容</a>
<div ui-view></div> <!-- 父View -->
</div>
</body>
<script type="text/javascript">
var app = angular.module('myApp', ['ui.router']);
app.config(["$stateProvider", function ($stateProvider) {
$stateProvider
.state("parent", {//父路由
url: '/parent',
template:'<div>parent'
+'<div ui-view><div>'// 子View
+'</div>'
})
.state("parent.child", {//子路由
url: '/child',
template:'<div>child</div>'
})
}]);
</script>
.state("parent.child", {
url: '^/child',
template:'<div>child</div>'
})
<body >
<div ng-app="myApp" >
<a ui-sref="index">点我显示index内容</a>
<div ui-view="header"></div>
<div ui-view="nav"></div>
<div ui-view="body"></div>
</div>
</body>
<script type="text/javascript">
var app = angular.module('myApp', ['ui.router']);
app.config(["$stateProvider", function ($stateProvider) {
$stateProvider
.state("index", {
url: '/index',
views:{
'header':{template:"<div>头部内容</div>"},
'nav':{template:"<div>菜单内容</div>"},
'body':{template:"<div>展示内容</div>"}
}
})
}]);
</script>
<body >
<div ng-app="myApp" >
<a ui-sref="index">show index</a>
<a ui-sref="index.content1">content111111</a>
<a ui-sref="index.content2">content222222</a>
<div ui-view="index"><div>
</div>
</body>
<script type="text/javascript">
var app = angular.module('myApp', ['ui.router']);
app.config(["$stateProvider", function ($stateProvider) {
$stateProvider
.state("index", {
url: '/index',
views:{
'index':{template:"<div><div ui-view='header'></div> <div ui-view='nav'></div> <div ui-view='body'></div> </div>"},
//这里必须要绝对定位
'header@index':{template:"<div>头部内容header</div>"},
'nav@index':{template:"<div>菜单内容nav</div>"},
'body@index':{template:"<div>展示内容contents</div>"}
}
})
//绝对定位
.state("index.content1", {
url: '/content1',
views:{
'body@index':{template:"<div>content11111111111111111</div>"}
//'body@index'表时名为body的view使用index模板
}
})
//相对定位:该状态的里的名为body的ui-view为相对路径下的(即没有说明具体是哪个模板下的)
.state("index.content2", {
url: '/content2',
views:{
'body':{template:"<div>content2222222222222222222</div>"}//
}
})
}]);
</script>
<body >
<div ng-app="myApp" >
<a ui-sref="index({id:30})">show index</a>
<a ui-sref="test({username:'peter'})">show test</a>
<div ui-view></div>
</div>
</body>
<script type="text/javascript">
var app = angular.module('myApp', ['ui.router']);
app.config(["$stateProvider", function ($stateProvider) {
$stateProvider
.state("home", {
url: '/',
template:"<div>homePage</div>"
})
.state("index", {
url: '/index/:id',
template:"<div>indexcontent</div>",
controller:function($stateParams){
alert($stateParams.id)
}
})
.state("test", {
url: '/test/:username',
template:"<div>testContent</div>",
controller:function($stateParams){
alert($stateParams.username)
}
})
}]);
</script>
<body >
<div ng-app="myApp" >
<a ui-sref="index">show index</a>
<div ui-view></div>
</div>
</body>
<script type="text/javascript">
var app = angular.module('myApp', ['ui.router']);
app.config(["$stateProvider", function ($stateProvider) {
$stateProvider
.state("home", {
url: '/',
template:"<div>homePage</div>"
})
.state("index", {
url: '/index/{id}',
template:"<div>indexcontent</div>",
resolve: {
//这个函数的值会被直接返回,因为它不是数据保证
user: function() {
return {
name: "peter",
email: "audiogroup@qq.com"
}
},
//这个函数为数据保证, 因此它将在控制器被实例化之前载入。
detail: function($http) {
return $http({
method: 'JSONP',
url: '/current_details'
});
},
//前一个数据保证也可作为依赖注入到其他数据保证中!(这个非常实用)
myId: function($http, detail) {
$http({
method: 'GET',
url: 'http://facebook.com/api/current_user',
params: {
email: currentDetails.data.emails[0]
}
})
}
},
controller:function(user,detail,myId$scope){
alert(user.name)
alert(user.email)
console.log(detail)
}
})
}]);
</script>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有