Error: [ng:areq] from angular controller

后端 未结 20 2176
攒了一身酷
攒了一身酷 2020-11-27 17:39

This is a long shot, but has anyone seen this error before? I am trying to add \'Transporters\' using express, angular and mongoDB. I get this error whenever I access a page

20条回答
  •  醉酒成梦
    2020-11-27 18:20

    I had done everything right other than setting controller in $stateProvider. I used filename rather than variable name.

    Following code is wrong:

    formApp.config(function($stateProvider, $urlRouterProvider) {
    
        $stateProvider
    
           .state('management', {
                url: '/management',
                templateUrl: 'Views/management.html',
                controller: 'Controllers/ManagementController.js'
            });
    

    and this is the right approach;

    formApp.config(function($stateProvider, $urlRouterProvider) {
    
        $stateProvider
    
           .state('management', {
                url: '/management',
                templateUrl: 'Views/management.html',
                controller: 'ManagementController'
            });
    

    Make sure you noticed;

    controller: 'ManagementController'

    And for those who are curious about my controller file ManagementController.js, it looks like the this;

    formApp.controller('ManagementController', ['$scope', '$http', '$filter', '$state',function(scope, http, filter, state) {
        scope.testFunc = function() {
            scope.managementMsg  = "Controller Works Fine.";
        };
    }]);
    

    For those who want a quick-start angular skeleton for above example check this link https://github.com/zaferfatih/angular_skeleton

提交回复
热议问题