【问题标题】:Does not show the view AngularJS不显示视图 AngularJS
【发布时间】:2016-12-04 21:02:56
【问题描述】:

我尝试展示带有角度路径的视图。控制台不会抛出任何错误或警告。

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

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 很多教程。

谢谢,他们可以帮忙。

【问题讨论】:

    标签: javascript angularjs controller routes electron


    【解决方案1】:

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

    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 注入控制器。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-12-28
      • 2023-03-04
      • 2015-03-29
      • 2018-09-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多