AngularJs-具有多个模块的应用程序

时间:2019-01-17 11:05:22

标签: angularjs

我有点卡住了。我尝试按照以下建议编写我的角度应用程序:https://github.com/johnpapa/angular-styleguide/tree/master/a1/i18n

但是我有这个公共错误:angular_v1.7.5.min.js:127错误:[$ controller:ctrlreg] http://errors.angularjs.org/1.7.5/ $ controller / ctrlreg?p0 = initController

有我的代码:

    //app.js
(function(angular) {
    'use strict';

    angular
        .module('app', [
            'orion.user'
        ])
        .controller('initController', ["$scope", 'orion.user', initController]);

    function initController($scope, user) {
        var vm = $scope;
        console.log(user)
    }})(window.angular);

// user.module.js
(function(angular) {
    'use strict';

    angular
        .module('orion.user', [
            'ngAnimate',
            'ngSanitize',
            'ngRoute'
        ]);

})(window.angular);

//index.html
<!doctype html>
<html lang="fr" ng-app="app" ng-controller="initController">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="theme-color" content="#fff">
    <meta name="viewport" content="width=device-width, user-scalable=yes, initial-scale=1">
    <meta http-equiv="cache-control" content="max-age=3600" />
    <meta http-equiv="Cache-control" content="public">

    <title>Test</title>  
</head>

<body>

    <script src="src/core/angular_v1.7.5.min.js"></script>
    <script src="src/core/angular-sanitize_v1.7.5.min.js"></script>
    <script src="src/core/angular-animate_v1.7.5.min.js"></script>
    <script src="src/core/angular-route_v1.7.5.min.js"></script>

    <script src="src/user/user.module.js"></script> 
    <script src="src/user/user.factory.js"></script>
    <script src="src/user/user.controler.js"></script>

    <script src="src/core/app.js"></script>

</body>

</html>

App.js是我的主应用程序,名为“ app”。我试图启动它调用用户模块。 有人可以向我解释我在做什么错吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

您没有正确注册控制器。

尝试:

   /app.js
(function(angular) {
    'use strict';

    angular
    .module('app', [
        'orion.user'
    ])
    .controller('initController', ["$scope", 'orion.user', initController]);

    function initController($scope, user) {
        var vm = $scope;
        console.log(user)
    }})(window.angular);
相关问题