AngularJS路由不能用一个简单的例子

时间:2016-11-28 11:57:16

标签: angularjs routing

对角度js和学习不熟悉。我尝试了一个非常简单的例子,但似乎一切都是正确的,但没有工作......我尝试使用两个简单的html文件进行路由。当点击用户列表时,html的内容应该放在ng-view div上。请帮忙...在此先感谢..下面是代码

  <!DOCTYPE html>
<html>
<head>
    <title>Main Page </title>
    <script src="js/angular.min.js"> </script>
    <script src="js/angular-route.min.js"></script>
    <script>
        var myApp = angular.module('myApp',['ngRoute']);

        myApp.config (function ($routeProvider) {

            $routeProvider

            .when('/', {
                templateUrl: 'pages/first.html',
                controller: 'FirstController'
            })

            .when('/Second', {
                templateUrl: 'pages/second.html',
                controller: 'SecondController'
            });

        });

        myApp.controller('FirstController',function($scope){



        });

        myApp.controller('SecondController',function($scope){


        });     


    </script>
</head>

<body ng-app="myApp">
    <ul>
        <li> Home Page</li>
        <li> <a href="#"> Go to First Page  </a>    </li>
        <li> <a href="#/Second"> Go to Second Page  </li>       
        <h1> Main Page is here</h1>     
    </ul>

    <div ng-view></div>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

您尚未关闭第二个</a>

  <ul>
        <li> Home Page</li>
        <li> <a href="#"> Go to First Page  </a>    </li>
        <li> <a href="#/Second"> Go to Second Page </a>  </li>       
        <h1> Main Page is here</h1>     
    </ul>

<强> DEMO