我是AngularJS的新手
我收到了这个错误:
Uncaught Error: [$injector:modulerr] Failed to instantiate module app due to:
Error: [$injector:modulerr] Failed to instantiate module ui.router due to:
Error: [$injector:nomod] Module 'ui.router' 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.
这是index.html文件:
<!doctype html>
<html ng-app="app">
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<meta charset="utf-8">
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Untitled</title>
<link rel="stylesheet" href="css/style.css">
<link rel="author" href="humans.txt">
</head>
<body ng-controller="FirstCtrl">
<input type="text" ng-model="first.greeting"/>
<div ng-class="first.greeting">{{first.greeting}}</div>
<script src="angular.js"></script>
<script src="app/app.js"></script>
<script src="js/main.js"></script>
</body>
</html>
这是app.js文件:
var app = angular.module("app", ["ui.router"]).controller("FirstCtrl", function FirstCtrl(){
var first = this;
first.greeting = "First";
});
请帮我解决这个问题
答案 0 :(得分:10)
你没有在ui-router脚本中加载,我不知道你是在本地使用它还是使用cdn,你只需要在index.html中添加它
例如,通过添加 -
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.15/angular-ui-router.min.js"></script>
index.html中的(这是一个cdn链接)
答案 1 :(得分:1)
通过以下步骤修复:
通过npm安装angular-ui-router
npm install angular-ui-router@0.2.18 --save
然后在index.html(angular 1.5.0)中加载脚本
<script src="node_modules/angular/angular.js"></script>
<script src="node_modules/angular-ui-router/release/angular-ui-router.js"></script>
答案 2 :(得分:0)
<script src="angular.js"></script>
这只是核心角度库,您需要下载并托管最新的角度ui路由器库或从CDN中提取它
请点击此处了解详情:https://github.com/angular-ui/ui-router
答案 3 :(得分:0)
可以通过nuget
安装PM&gt;安装包Angular.UI.UI-Router