Angular + requirejs Controller logging error

Asked

Viewed 212 times

0

I’m starting an application with Angular + Requirejs. Follow below

Main.js

;(function (doc, undefined) {
'use strict';

var $scriptDefault = doc.querySelector('[data-js="script-default"]');
var BASE_URL = $scriptDefault.getAttribute('data-base-url');

require.config({
    baseUrl: '/js',
    paths: {
        jquery: [
            'https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min',
            'vendor/jquery'
        ],
        lodash: 'vendor/lodash',
        angular: '../bower_components/angular/angular.min',
        ngRoute: '../bower_components/angular-route/angular-route.min',
        domReady: '../bower_components/requirejs-domready/domReady',
    },
    shim: {
        'angular': {
            exports: 'angular',
            deps: ['jquery']
        },

        'ngRoute': {
            deps: ['angular']
        },
        'newApp': {
            deps: [
                'angular',
                'ngRoute'
            ]
        }
    },
    deps: [
        // kick start application... see bootstrap.js
        './bootstrap'
    ]
});

})(document);

App.js

'use strict'
define([
    'angular'
], function () {
    var app = angular.module('sisge', ['ngRoute']);
    app.config(function ($routeProvider, $locationProvider) {

        $routeProvider
            .when('/', {
                templateUrl: '../app/modules/dashboard/dashboard.html',
                controller: "DashboardCtrl"
            })
            .when('/usuarios', {
                templateUrl: '../app/modules/usuarios/list.html',
                controller: 'ListUsuarioCtrl',
            })
            .when('/ligas', {
                templateUrl: '../app/modules/ligas/list.html',
                controller: 'ListLigaCtrl',
            })
            .otherwise ({ redirectTo: '/' });

        $locationProvider.html5Mode(true);

    });
return app;
});

bootstrap.js

    define([
        'require',
        'angular',
        'newApp',

    ], function (require, ng) {
        'use strict';

        require(['domReady!'], function (document) {
            ng.bootstrap(document, ['app']);
        });
    });

dashboardCtrl.js

'use strict';
    define([
        '../module'
    ], function (controllers) {
        'use strict';
        controllers.controller('DashboardCtrl', [
            '$scope',

            function ($scope) {
                $scope.message = "Muito bom";
                $scope.text = 'Agora sim dando certo';
                $scope.label = 'caramba';
            }

        ]);
    });

module js.

define([
        'angular'
    ], function (angular) {
        'use strict';
        return angular.module('app.controllers', []);
    });

I am having the following controller registration error as if it was not loaded, but it appears on network as loaded page:

angular.js:14642 Error: [$controller:ctrlreg] http://errors.angularjs.org/1.6.5/$controller/ctrlreg? P0=Dashboardctrl

Can anyone help?

1 answer

0


Missed you set the Controllers on App.js, you are calling him but he was not created. For more details, see the documentation.

app.controller('DashboardCtrl', ['$scope', function ($scope) {
    $scope.titulo = 'Dashboard';
}]);
  • Sorry Wéllingthon, I forgot to put the controller in the post...

  • See if this tutorial can help you, there is no way I do tests at the moment.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.