Error: [$injector:modulerr] Failed to instantiate module phonecatApp

Error: [$injector:modulerr] Failed to instantiate module phonecatApp #216

@mr-sachinkalekar @petebacondarwin @pjprogrammer1953
@mr-sachinkalekar

I try running the index.html at step number 7. It is just showing blank html page. And when i go to the debugger it says the above error

Error: [$injector:modulerr] Failed to instantiate module phonecatApp due to:
[$injector:modulerr] Failed to instantiate module ngRoute due to:
[$injector:nomod] Module 'ngRoute' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.

@mr-sachinkalekar mr-sachinkalekar changed the title from  Error: [$injector:modulerr] Failed to instantiate module phonecatApp due to: [$injector:modulerr] Failed to instantiate module ngRoute due to: [$injector:nomod] Module 'ngRoute' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument. to Error: [$injector:modulerr] Failed to instantiate module phonecatApp  on 28 Nov 2014
@petebacondarwin
Owner

This sounds like you do not have ngRoute loaded.
Have you:

  • added it to bower.json// 原因之一,就是你没有add一个bower.json把angular.js文件版本加载进去
  • run npm install (to trigger bower install)//安装npm
  • added as a script tag it to the index.html//原因之二,增加一个script标签在index.html页面中。
@mr-sachinkalekar

I am using Apache tomcat server to run this tutorial. I loaded the ngRoute from the CDN //ajax.googleapis.com/ajax/libs/angularjs/X.Y.Z/angular-route.js Its still showing the same error. Is there any other way of loading ngRoute in Apache tomcat

@petebacondarwin
Owner

You can totally load it from the CDN. I guess you are not using the actual URL you gave... but replacing the X.Y.Z with the real version number?
Can you check that the file is downloading correctly?

@mr-sachinkalekar

i am loading the file from the local disk and now it says 
TypeError: angular is undefined

@petebacondarwin
Owner
@mr-sachinkalekar

index.html:

//<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
//<html ng-app="phonecatApp">
//<head>
    //<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    //<title>Phone Gallery</title>
    //<script src="js/angular-route.js"></script>
    //<script src="js/angular.js"></script>
    //<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet">
    //<script src="js/app.js"></script>
    //<script src="js/controllers.js"></script>
    //<script src="css/app.css"></script>
//</head>
//<body>
    //<div ng-view>

    //</div>
//</body>
//</html> */

controllers.js:

'use strict';
/* Controllers */
var phonecatControllers = angular.module('phonecatControllers', []);
phonecatControllers.controller('PhoneListCtrl', ['$scope', '$http',
         function($scope, $http) {
            $http.get('phones/phones.json').success(function(data) {
            $scope.phones = data;
         });
         $scope.orderProp = 'age';
    }]);

phonecatControllers.controller('PhoneDetailCtrl', ['$scope', '$routeParams',
         function($scope, $routeParams) {
            $scope.phoneId = $routeParams.phoneId;
        }
]);

app.js:

'use strict';
/* App Module */
var phonecatApp = angular.module('phonecatApp', [
    'phonecatControllers',
    'ngRoute'
]);
phonecatApp.config(['$routeProvider',
    function($routeProvider) {
            $routeProvider.
                when('/phones', {
                    templateUrl: 'phone-list.html',
                    controller: 'PhoneListCtrl'
                }).
                when('/phones/:phoneId', {
                    templateUrl: 'phone-detail.html',
                    controller: 'PhoneDetailCtrl'
                }).
                    otherwise({
                    redirectTo: 'phones'
                });
    }
]);

phone-detail.html:

TBD: detail view for <span>{{phoneId}}</span>

phone-list.html:

<div class="container-fluid">
    <div class="row">
        <div class="col-md-2">
        <!--Sidebar content-->
            Search: <input ng-model="query">
            Sort by:
            <select ng-model="orderProp">
            <option value="name">Alphabetical</option>
            <option value="age">Newest</option>
            </select>
        </div>
    <div class="col-md-10">
    <!--Body content-->
            <ul class="phones">
                <li ng-repeat="phone in phones | filter:query | orderBy:orderProp" class="thumbnail">
                    <!-- <a href="/phones/{{phone.id}}" class="thumb"><img ng-src="{{phone.imageUrl}}"></a>
                    <a href="/phones/{{phone.id}}">{{phone.name}}</a> -->
                    <p>{{phone.snippet}}</p>
                </li>
            </ul>
        </div>
    </div>
</div>

The rest of the files(angular.js,angular-route.js,phones.json) are same as in angular-phonecat and are at the locations as mentioned in the code.
Thanks a lot for your time. Have a happy weekend.

@petebacondarwin
Owner

OK, so you need to load angular-route.js after angular.js//这句话是重点,就是说,你应该加载angular-route.js放在angular.js之后,当angular.js加载之后才能使用其他,因为angular.js是核心。

@mr-sachinkalekar
@pjprogrammer1953

I had the same problem as mr-sachinkalekar, struggled with it for days, and confounded my code school instructor and teacher assistant with it. Mr petebacondarwin's advice fixed the problem, which was so simple to resolve with proper module installation and configuration.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值