Error: [ng:areq] from angular controller

后端 未结 20 1973
攒了一身酷
攒了一身酷 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:21

    I had same error and the issue was that I didn't inject the new module in the main application

    var app = angular.module("geo", []);
    ...
    
    angular
        .module('myApp', [
            'ui.router',
            'ngResource',
            'photos',
            'geo' //was missing
        ])
    
    0 讨论(0)
  • 2020-11-27 18:21

    The same problem happened with me but my problem was that I wasn't adding the FILE_NAME_WHERE_IS_MY_FUNCTION.js

    so my file.html never found where my function was

    Once I add the "file.js" I resolved the problem

    <html ng-app='myApp'>
        <body ng-controller='TextController'>
        ....
        ....
        ....
        <script src="../file.js"></script>
        </body>
    </html>
    

    :)

    0 讨论(0)
  • 2020-11-27 18:24

    I ran into this issue when I had defined the module in the Angular controller but neglected to set the app name in my HTML file. For example:

    <html ng-app>
    

    instead of the correct:

    <html ng-app="myApp">
    

    when I had defined something like:

    angular.module('myApp', []).controller(...
    

    and referenced it in my HTML file.

    0 讨论(0)
  • 2020-11-27 18:24

    I've got that error when the controller name was not the same (case sensitivity!):

    .controller('mainCOntroller', ...  // notice CO
    

    and in view

    <div class="container" ng-controller="mainController">  <!-- notice Co -->
    
    0 讨论(0)
  • 2020-11-27 18:26

    I got this same error when I included the entire controller file name in the Routes like this:

    app.config(function($routeProvider) {
        $routeProvider 
        .when('/', { 
            templateUrl: 'home.html',
            controller: 'mainController.js'
        })
    
        .when('/portfolio', { 
            templateUrl: 'portfolio.html',
            controller: 'mainController.js'
        })
    });
    

    When it should be

    app.config(function($routeProvider) {
        $routeProvider 
        .when('/', { 
            templateUrl: 'home.html',
            controller: 'mainController'
        })
    
        .when('/portfolio', { 
            templateUrl: 'portfolio.html',
            controller: 'mainController'
        })
    });
    

    Angular takes certain things you name like the app and controller and expounds on them in directives and across your app, take care to name everything consistently and check for this when debugging

    0 讨论(0)
  • 2020-11-27 18:26

    I have made a stupid mistake and wasted lot of time so adding this answer over here so that it helps someone

    I was incorrectly adding the $scope variable(dependency)(was adding it without single quotes)

    for example what i was doing was something like this

    angular.module("myApp",[]).controller('akshay',[$scope,
    

    where the desired syntax is like this

    angular.module("myApp",[]).controller('akshay',['$scope',
    
    0 讨论(0)
提交回复
热议问题