Home > Web Front-end > JS Tutorial > body text

How to Fix \'Uncaught Error: [$injector:modulerr]\' When Migrating to AngularJS v1.3?

Susan Sarandon
Release: 2024-11-01 04:13:27
Original
752 people have browsed it

How to Fix

AngularJS: Uncaught Error: [$injector:modulerr] When Migrating to V1.3

In AngularJS version 1.3, global controller function declaration is no longer permitted. Instead, developers must create an AngularJS module and attach components to it.

To resolve the error, follow these steps:

  • Create an AngularJS module using angular.module('app', []).
  • Attach the controller to the module using .controller('Ctrl', ['$scope', Ctrl]).

For example:

<code class="js">function Ctrl($scope) {
    $scope.age = 24;
}

angular.module('app', [])
    .controller('Ctrl', ['$scope', Ctrl]);</code>
Copy after login

Note: AngularJS version 1.3.14 has some issues with this approach, so consider downgrading to version 1.3.13 or using AngularJS 1.6.X for a more stable experience.

Plunkr Example (AngularJS 1.3.13):

https://plnkr.co/edit/Ei7P5xJ5NCKz9UEFyWij

Alternative Solution:

If you prefer to continue using global controller declaration, you can allow it within angular.config, although this is not the recommended approach:

<code class="js">angular.module('app', [])
    .config(['$controllerProvider',
        function ($controllerProvider) {
            $controllerProvider.allowGlobals();
        }
    ]);</code>
Copy after login

The above is the detailed content of How to Fix \'Uncaught Error: [$injector:modulerr]\' When Migrating to AngularJS v1.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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!