您好Angular UI-router有一个奇怪的问题。我正要更新一个webapp,并希望用Angular来做这件事。我听说过很多关于UI路由器的好东西,但我没有让它工作。我正在按照有关如何设置视图的教程,但收到错误:Uncaught Error: [$injector:modulerr] Failed to instantiate module fqmApp due to:
TypeError: undefined is not a function
我正在使用cdn'来导入angular和ui-router。这是我的确切代码:
<!doctype html>
<html ng-app="fqmApp">
<head>
<script src="https://code.angularjs.org/1.3.9/angular.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.13/angular-ui-router.min.js"></script>
<script src="app.js"></script>
</head>
<body>
<div ui-view>
</div>
<a ui-sref="state1">State 1</a>
<a ui-sref="state2">State 2</a>
</body>
</html>
JS
"use strict"
angular.module("fqmApp", ["ui.router"])
.config(function ($stateProvider, $urlRouterProvider) {
//For any unmatched url, redirect to /state1
$urlRouterProvider.otherwhise("/state1");
//Now set up the states
$stateProvider
.state('state1', {
url: "/state1",
templateUrl: "partials/state1.html"
})
.state('state2', {
url: "/state2",
templateUrl: "partials/state2.html"
});
})
.controller("ctrl", function ($scope) {
$scope.hello="hello";
})
如果我不包含配置服务代码,一切正常。我不知道我在哪里错了。控制器只是一个测试。它工作正常。这可能是一些愚蠢的错误,但我现在已经看了一个小时或更长时间。
有人看到了这个问题吗?提前谢谢。
答案 0 :(得分:1)
代码的问题在于你有一个拼写错误,它应该否则而不是 otherwhise 更改此部分:
$urlRouterProvider.otherwhise("/state1");
在此:
$urlRouterProvider.otherwise("/state1");