zoukankan      html  css  js  c++  java
  • 路由传参数

     <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>

  • 相关阅读:
    http statusCode(状态码) 200、300、400、500序列
    一行css代码调试中学到的javascript知识,很有意思
    jquery中的cookie
    图片预加载和AJAX的图片预加载
    关于图片懒加载
    iframe的自适应
    阻止微信端浏览器下滑出现空白条现象
    动态加载js文件
    kaldi 的安装和测试
    Python算法-排序
  • 原文地址:https://www.cnblogs.com/zzwerzi/p/7568168.html
Copyright © 2011-2022 走看看