Error: [$injector:modulerr] Failed to instantiate module phonecatApp
来源:互联网 发布:drilldown.js 编辑:程序博客网 时间:2024/05/19 02:43
Error: [$injector:modulerr] Failed to instantiate module phonecatApp #216
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页面中。
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
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?
i am loading the file from the local disk and now it says
TypeError: angular is undefined
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.
OK, so you need to load angular-route.js
after angular.js//这句话是重点,就是说,你应该加载angular-route.js放在angular.js之后,当angular.js加载之后才能使用其他,因为angular.js是核心。
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.
- Error: [$injector:modulerr] Failed to instantiate module phonecatApp
- Uncaught Error: [$injector:modulerr]
- AngularJS: Error reports on $injector:modulerr
- angular.js:4411 Uncaught Error: [$injector:modulerr]
- angular.js 错误:Error: [$injector:modulerr] 原因
- Uncaught SyntaxError: Unexpected identifier和 Uncaught Error: [$injector:modulerr]
- 初探angular之[$injector:modulerr]
- grunt error $injector module is not available
- Error: [$injector:nomod] Module 'dayApp' is not available!
- configure: error: failed to find required module google.protobuf
- FAILED: Error in metadata: java.lang.RuntimeException: Unable to instantiate org.apache.解决办法
- FAILED: Error in metadata: java.lang.RuntimeException: Unable to instantiate org.apache.解决办法
- FAILED: Error in metadata: java.lang.RuntimeException: Unable to instantiate org.apache.解决办法
- FAILED: Error in metadata: java.lang.RuntimeException: Unable to instantiate org.apache.解决办法
- FAILED: Error in metadata: java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.
- FAILED: Error in metadata: java.lang.RuntimeException: Unable to instantiate org.apache.解决办法
- Hive出现异常 FAILED: Error In Metadata: Java.Lang.RuntimeException: Unable To Instantiate Org.Apache.Had
- hive 报错FAILED: Error in metadata: java.lang.RuntimeException: Unable to instantiate org.apache.hadoo
- 每日一模块——BeautifulSoup4
- SQLite表结构和数据的导入导出
- 关于get_opt()
- 非监督遥感影像变化检测方法——支持向量机(support vector machine,SVM )
- ios uiapplication 代理appdelegate
- Error: [$injector:modulerr] Failed to instantiate module phonecatApp
- 在java中常出现的异常和解决方法
- python基础之安装python
- 360 Android 插件项目 DroidPlugin
- Linux 如何在文件里搜索关键字
- Gradle for Android
- html动态显示时间
- Linux中随手可得的测试、调试、性能检验工具
- python boto AWS SQS connection
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.