zoukankan      html  css  js  c++  java
  • Angular之ngRoute与uiRoute

    ngRoute不支持嵌套路由

    用法如下:

     1 <!DOCTYPE html>
     2 <html lang="en" ng-app="myApp">
     3 <head>
     4     <meta charset="UTF-8">
     5     <meta name="viewport" content="width = device-width, initial-scale = 1.0, maximum-scale = 1.0, user-scalable = 0" />
     6     <title>angular 路由</title>
     7 </head>
     8 <style>
     9     ul li{
    10         list-style: none;
    11         float: left;
    12         padding: 10px;
    13     }
    14 </style>
    15 <body>
    16     <ul>
    17         <li><a href="#page1">page1</a></li>
    18         <li><a href="#page2">page2</a></li>
    19         <li><a href="#page3">page3</a></li>
    20     </ul>
    21     <div ng-view></div>
    22 </body>
    23 <script src="./script/libs/angularjs.1.4.6.min.js"></script>
    24 <script src="./script/libs/angular-route.js"></script>
    25 <script>
    26     angular.module('myApp',['ngRoute'])
    27     .config(function($routeProvider){
    28         $routeProvider.when("/page1",{
    29             template:"this is page1"
    30         }).when("/page2",{
    31             template:"this is page2"
    32         }).when("/page3",{
    33             template:"this is page3"
    34         }).otherwise({
    35             redirectTo:"/page1"   //默认路由
    36         })
    37     });
    38 </script>
    39 </html>

    uiRouter支持嵌套路由

    用法如下:

     1 <!DOCTYPE html>
     2 <html lang="en" ng-app="myApp">
     3 <head>
     4     <meta charset="UTF-8">
     5     <meta name = "viewport" content = "width = device-width, initial-scale = 1.0, maximum-scale = 1.0, user-scalable = 0" />
     6     <title>angular路由</title>
     7 </head>
     8 <style>
     9     ul li{
    10         list-style: none;
    11         float: left;
    12         padding: 10px;
    13     }
    14 </style>
    15 <body>
    16     <ul>
    17         <li><a href="#page1">page1</a></li>
    18         <li><a href="#page2">page2</a></li>
    19         <li><a href="#page3">page3</a></li>
    20     </ul>
    21     <div ui-view></div>
    22 </body>
    23 <script src="./script/libs/angularjs.1.4.6.min.js"></script>
    24 <script src="./script/libs/angular-ui-router.js"></script>
    25 <script>
    26     angular.module('myApp',['ui.router'])
    27     .config(function($stateProvider,$urlRouterProvider){
    28         $stateProvider.state('page1',{
    29             url:"/page1",
    30             template:"this is p1"
    31         }).state('page2',{
    32             url:"/page2",
    33             template:"this is p2"
    34         }).state('page3',{
    35             url:"/page3",
    36             template:"this is p3"
    37         });
    38         $urlRouterProvider.otherwise('page1');
    39     });
    40 </script>
    41 </html>
  • 相关阅读:
    HDU 5400 Arithmetic Sequence
    poj 3041 Asteroids
    后缀自己主动机(SAM)学习指南
    【POJ3740】Easy Finding DLX(Dancing Links)精确覆盖问题
    高速幂小模板
    有用函数编程
    将C++的标识符转成OC的标识符
    【翻译自mos文章】oracle db 中的用户账户被锁--查看oracle用户的尝试次数
    Hibernate基础-HelloWord
    Android项目之HomeHealth基础学习2:Service
  • 原文地址:https://www.cnblogs.com/happy1992/p/7136263.html
Copyright © 2011-2022 走看看