搜索

首页  >  问答  >  正文

angular.js - angularjs通过锚链接实现页面切换的问题

<!DOCTYPE html>
<html>
<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>
    //<script src="js/angular.js"></script>
</head>
<body ng-app="ngView">


<p ng-view>
</p>





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



</body>
</html>

通过cdn方式进行angular文件引入时在火狐浏览器中可以实现,chrome不可以。当通过本地文件进行angular引入时提示:
Uncaught Error: [$injector:modulerr] Failed to instantiate module ngView due to:
Error: [$injector:unpr] Unknown provider: $routeProvider
http://errors.angularjs.org/1.3.16/$injector/unpr?p0=$routeProvider
at file:///C:/wamp/www/js/angular.js:63:12
at file:///C:/wamp/www/js/angular.js:4031:19
at getService (file:///C:/wamp/www/js/angular.js:4178:39)
at Object.invoke (file:///C:/wamp/www/js/angular.js:4210:13)
at runInvokeQueue (file:///C:/wamp/www/js/angular.js:4125:35)
at file:///C:/wamp/www/js/angular.js:4134:11
at forEach (file:///C:/wamp/www/js/angular.js:326:20)
at loadModules (file:///C:/wamp/www/js/angular.js:4115:5)
at createInjector (file:///C:/wamp/www/js/angular.js:4041:11)
at doBootstrap (file:///C:/wamp/www/js/angular.js:1455:20)
http://errors.angularjs.org/1.3.16/$injector/modulerr?p0=ngView&p1=Error:…otstrap (file:///C:/wamp/www/js/angular.js:1455:20)

巴扎黑巴扎黑2786 天前566

全部回复(1)我来回复

  • PHP中文网

    PHP中文网2017-05-15 16:55:13

    你没有引入angular-route

    回复
    0
  • 取消回复