简单的 ng-Route 在 ng-View 中不起作用

Simple ng-Route not working in ng-View

我有一个简单的示例,其中默认值 one.html 必须对 ng-Route 可见,但我却收到错误消息。

HTML:

<html>
<head>
<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<script src="http://code.angularjs.org/1.2.1/angular-route.min.js"></script>
<script src= "angularScript.js"></script>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
<div ng-view=""></div>
</body> 
</html>

angularScript.js

//App Declaration 
var app = angular.module('myApp', ['ng-Route'] );

//Controllers 
app.controller('myCtrl', function($scope) {

});

//Routers 
app.config(function($routeProvider){

    $routeProvider
    .when('/one', {
        title: 'one',
        controller: 'oneCtrl',
        templateUrl: 'one.shtml'
    })  
    .when('/two', {
        title: 'two',
        controller: 'twoCtrl',
        templateUrl: 'two.shtml'
    })  
    .when('/three', {
        title: 'three',
        controller: 'threeCtrl',
        templateUrl: 'three.shtml'
    })  
    .otherwise({
        title: 'one',
        redirectTo: '/one'
    });
});

one.html

This is one

我正在依赖 ng-Route 并尝试使用 ng-view 在 div 的页面中获取默认的 one.html 内容,但我在控制台上收到以下错误:

Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.3.14/$injector/modulerr?p0=myApp&p1=Error%3A%…gleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.3.14%2Fangular.min.js%3A17%3A381)

在您的 angularjs 脚本中尝试以下代码

    //App Declaration 
var app = angular.module('myApp', ['ngRoute'] );

//Controllers 
app.controller('myCtrl', function($scope) {

});
app.controller('oneCtrl', function($scope) {

});
//Routers 
app.config(function($routeProvider){

    $routeProvider
    .when('/one', {
        title: 'one',
        controller: 'oneCtrl',
        templateUrl: 'one.shtml'
    })  
    .when('/two', {
        title: 'two',
        controller: 'twoCtrl',
        templateUrl: 'two.shtml'
    })  
    .when('/three', {
        title: 'three',
        controller: 'threeCtrl',
        templateUrl: 'three.shtml'
    })  
    .otherwise({
        title: 'one',
        redirectTo: '/one'
    });
});

你需要在controller中指定oneCtrl和ngRoute