<script>
// 创建一个主模块 - 注意添加对ngRoute路由模块的依赖
var myapp = angular.module("myapp", ["ngRoute"]);
// 路由配置
myapp.config(function($routeProvider){
$routeProvider.when("/",{
"templateUrl":"pages/home.html",
"controller":"homeCtrl"
}).when("/about",{
"templateUrl":"pages/about.html",
"controller":"aboutCtrl"
}).when("/contact",{
"templateUrl":"pages/contact.html",
"controller":"contactCtrl"
}).when("/contact/:name",{
"templateUrl":"pages/contact.html",
"controller":"contactCtrl"
})
});
// 注册多个控制器
myapp.controller("homeCtrl",function($scope){
$scope.message="这是首页"
});
myapp.controller("aboutCtrl",function($scope){
$scope.message="这是about页"
});
myapp.controller("contactCtrl",function($scope,$routeParams){
$scope.message="这是contactCtrl页";
console.log($routeParams);
if($routeParams.name=="a"){
$scope.title="我想告诉";
}else if($routeParams.name=="b"){
$scope.title="我想询价";
}
});
</script>
<nav class="navbar navbar-default">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="#/">我的站点</a>
</div>
<ul class="nav navbar-nav navbar-right">
<li><a href="#/"><i class="fa fa-home"></i>主页</a></li>
<li><a href="#about"><i class="fa fa-shield"></i> 关于我们</a></li>
<li><a href="#contact"><i class="fa fa-comment"></i> 联系我们</a></li>
</ul>
</div>
</nav>
</header>
<div id="main">
<!--子视图切换在这里-->
<div ng-view></div>