search

Home  >  Q&A  >  body text

angular.js - AngularJs通过定义锚点链接控制页面输出

<!DOCTYPE html>
<html ng-app="ngView">
<head>
    <title>分页显示</title>
    <meta charset="utf-8">
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script> 
    <script src="http://code.angularjs.org/angular-1.0.1.min.js"></script>
</head>
<body>


<p ng-view>
    <p  ng-controller="test">
        
    </p>
</p>





<script type="text/javascript">
 angular.module('ngView', [],
    function($routeProvider){
      $routeProvider.when('/test1',
        {
          templateUrl: 'demo.html',
          controller: 'test'
        }
      )
      .when('/test2',
      {
        templateUrl:'slinder.html',
        controller: 'test'
      }
      );
    }
  );
</script>


</body>
</html>

挡在url中输出/#/test1时demo.html没有显示,请问是什么情况??

大家讲道理大家讲道理2739 days ago666

reply all(1)I'll reply

  • 天蓬老师

    天蓬老师2017-05-15 16:55:14

    Tell me a few questions
    1: ng-app is generally written in the body
    2: When defining routes, it is best to write them in a $routeProvider
    3: Your routing definition is wrong. You only write the template without specifying the controller, which is also the reason why it does not work.

    reply
    0
  • Cancelreply