Home > Web Front-end > JS Tutorial > How to Fix 'Argument 'ContactController' is not a function' Errors in Angular 1.3 ?

How to Fix 'Argument 'ContactController' is not a function' Errors in Angular 1.3 ?

Linda Hamilton
Release: 2024-12-01 21:56:14
Original
473 people have browsed it

How to Fix

Issue: Global Controller Declaration Error

Angular 1.3 has deprecated the use of global controller declarations on the global scope. This issue manifests as an error stating "Argument 'ContactController' is not a function, got undefined," preventing controllers from being defined globally without explicit registration.

Solution: Register Controllers with Module Syntax

To fix this, controllers should be registered using the module.controller syntax. For example:

angular.module('app', []).controller('ContactController', ['$scope', function ContactController($scope) {
  // Controller logic
}]);
Copy after login

Alternatively, you can inject the controller as a function:

function ContactController($scope) {
  // Controller logic
}
ContactController.$inject = ['$scope'];
angular.module('app', []).controller('ContactController', ContactController);
Copy after login

Turning on Globals

If you prefer to use global declarations, you can enable them by setting allowGlobals in the $controllerProvider.

angular.module('app')
  .config(['$controllerProvider', function($controllerProvider) {
    $controllerProvider.allowGlobals();
  }]);
Copy after login

Additional Notes

  • Ensure that your app name is included in the ng-app directive on the root element (e.g., ng-app="myApp").
  • Verify that the correct scripts are included.
  • Avoid defining the same module twice in different locations, as this can overwrite previously registered entities.

The above is the detailed content of How to Fix 'Argument 'ContactController' is not a function' Errors in Angular 1.3 ?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template