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:
For example:
<code class="js">function Ctrl($scope) { $scope.age = 24; } angular.module('app', []) .controller('Ctrl', ['$scope', Ctrl]);</code>
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>
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!