Uncaught Referenceerror: angular is not defined

Asked

Viewed 3,358 times

1

I am in trouble because I am studying routes in angular and I came across the errors sequintes in the console

Uncaught ReferenceError: angular is not defined
at app.js:1

and also this

Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.4.8/$injector/modulerr?p0=app&p1=Error%3A%20%5B%24injector%3Anomod%5D%20http%3A%2F%2Ferrors.angularjs.org%2F1.4.8%2F%24injector%2Fnomod%3Fp0%3Dapp%0A%20%20%20%20at%20http%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.4.8%2Fangular.min.js%3A6%3A416%0A%20%20%20%20at%20http%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.4.8%2Fangular.min.js%3A24%3A186%0A%20%20%20%20at%20b%20(http%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.4.8%2Fangular.min.js%3A23%3A251)%0A%20%20%20%20at%20http%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.4.8%2Fangular.min.js%3A23%3A494%0A%20%20%20%20at%20http%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.4.8%2Fangular.min.js%3A38%3A117%0A%20%20%20%20at%20n%20(http%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.4.8%2Fangular.min.js%3A7%3A333)%0A%20%20%20%20at%20g%20(http%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.4.8%2Fangular.min.js%3A37%3A488)%0A%20%20%20%20at%20eb%20(http%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.4.8%2Fangular.min.js%3A41%3A249)%0A%20%20%20%20at%20c%20(http%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.4.8%2Fangular.min.js%3A19%3A463)%0A%20%20%20%20at%20yc%20(http%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.4.8%2Fangular.min.js%3A20%3A274)
at angular.js:38
at angular.js:4458
at n (angular.js:340)
at g (angular.js:4419)
at eb (angular.js:4344)
at c (angular.js:1676)
at yc (angular.js:1697)
at Zd (angular.js:1591)
at angular.js:29013
at HTMLDocument.b (angular.js:3057)

here is my index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">

    <title>Document</title>
</head>
<script type="text/javascript" src="app.js"></script>
<script src="node_modules/angular/angular.js"></script>
<script src="node_modules/angular-route/angular-route.js"></script>

<body ng-app="app">
    <h1>Este e um exemplo de single page</h1>
    <a href="#/">Home</a>
    <a href="#/sobre">Sobre</a>

    <div ng-view></div>

</body>
</html>

and here the app.js

var app = angular.module('app', ['ngRoute']);
app.route(function($routeprovider){
    $routeprovider
        .when("/", {
            templateUrl : "templates/home.html"
        })
        .when("/about", {
            templateUrl : "templates/sobre.html"
        });

});

I’ve seen the previous posts not solved anything I’m using the angular and angular-route both are 1.6 using the NPM for the dependencies if anyone can help me thank you.

  • Are you sure the version is 1.6 ? Because the error log is 1.4.8 ... Just access to URL which is on the first line Uncaught Error: [$injector:modulerr] http://errors.angularjs.org

1 answer

0


I recreated this example in plnkr and made some modifications that worked:

1 - use app.config() instead of app.route(),

2 - use $routeProvider instead of $routeprovider (note the uppercase "P")

I used angular version 1.6 for this test that you can check out in this Plunk

Browser other questions tagged

You are not signed in. Login or sign up in order to post.