不显示视图 AngularJS

Does not show the view AngularJS

我尝试显示具有 angular 路径的视图。控制台不会抛出任何错误或警告。

但同样视图不显示。 我做错了什么?

index.html

<!DOCTYPE html>
<html lang="en" ng-app="app">
<head></head>
    <body>

        <ng-view></ng-view>

        <!-- build:js bower/vendor -->
        <script type="text/javascript" src="../bower_components/angular/angular.min.js"></script>
        <script src="../bower_components/angular-route/angular-route.min.js"></script>
        <!-- endbuild -->

        <script src="./routes.js"></script>

        <!-- build:app scripts/js || CUSTOMER -->
        <script src="./components/customer/customerService.js"></script>
        <script src="./components/customer/customerController.js"></script>
        <!-- endbuild-->

    </body>
</html>

routes.js

var _templateBase = './components';

angular.module('app', [
    'ngRoute'
])
.config(['$routeProvider', function ($routeProvider) {
        $routeProvider
        .when('/', {
            templateUrl: _templateBase + '/customer/customer.html' ,
            controller: 'customerController',
            controllerAs: '_ctrl'
        })
        .otherwise({
            redirectTo: '/'
         });
    }
]);

costomerService.js

angular.module('app', [])
        .factory('customerService', function() {

        });

costomerController.js

angular.module('app',[])
    .controller('customerController', ['$scope', function($scope, customerService) {
      //
    }]);

错了?因为视图没有显示?我正在使用过时的 mertodos,指导我 lleguar 那里的许多教程。

谢谢,所以他们可以提供帮助。

这会创建您的应用程序,因为您包含了第二个参数(要注入的依赖项数组):

angular.module('app', [
    'ngRoute'
])

删除其他 angular.module() 定义中的第二个参数,因为这会导致每次都创建一个新的应用程序。

angular.module('app') <-- no second parameter tells it to use the existing 'app' module 
    .factory('customerService', function() {

    });

angular.module('app') <-- no second parameter tells it to use the existing 'app' module
    .controller('customerController', ['$scope', 'customerService', function($scope, customerService) {
      //
    }]);

我在你的控制器定义中添加了 customerService 到你的注入数组,因为数组元素必须与你的函数参数完全匹配。 此外,如果您像在路由定义中那样使用 controllerAs 语法,那么您可能不想将 $scope 注入控制器。