Angular 1.4.5 : Uncaught Error: [$injector:modulerr] ngRoute

落爺英雄遲暮 提交于 2019-12-05 09:46:37

Basically its typographical mistake.

It should be

<html ng-app='myapp'>

Instead of

<html ng-app='myApp'>

Additionally correct your script tags like below.

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script>
<script src="https://code.angularjs.org/1.4.5/angular-route.js"></script>          
<script src="app.js"></script>
var app = angular.module("myApp", ["ngRoute"]);
app.config(function( $routeProvider ) {
    $routeProvider
    .when("/home", {
        template : "<h1>Main</h1><p>Click on the links to change this content</p>"
    })
    .when("/red", {
        templateUrl : "red.htm"
    })
    .when("/green", {
        templateUrl : "green.htm"
    })
    .when("/blue", {
        templateUrl : "blue.htm"
    });
});

In my case I used $routeProvider.when({}) without url as first parameter and that was the case, when I add the url like below, error was gone.

$routeProvider.when('/post/:id', {
   templateUrl: 'views/post.html',
   controller: 'PostController'
}) 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!