angular.js - angularjs透過錨定連結實現頁面切換的問題
巴扎黑
巴扎黑 2017-05-15 16:53:13
0
1
512
<!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=%24routeProvider
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 %3A…otstrap%20(file%3A%2F%2F%2FC%3A%2Fwamp%2Fwww%2Fjs%2Fangular.js%3A1455%3A20)

巴扎黑
巴扎黑

全部回覆(1)
Ty80

你沒有引入angular-route

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!