[英]Angular ui-router is not instantiated, giving an inject module error
您好,我對Angular UI-router有一個奇怪的問題。 我正要續訂一個Webapp,並想用Angular做到這一點。 我聽說過很多有關UI-router的好東西,但是我沒有使它起作用。 我正在按照有關如何設置視圖的教程進行操作,但出現錯誤: Uncaught Error: [$injector:modulerr] Failed to instantiate module fqmApp due to: TypeError: undefined is not a function
我正在使用CDN導入角度和ui路由器。 這是我的確切代碼:
<!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";
})
如果我不包含配置服務代碼,一切都會正常。 我在這里沒錯。 控制器只是一個測試。 工作正常。 這可能是一個愚蠢的錯誤,但是我已經看了一個小時或更長時間了。
有人看到問題了嗎? 提前致謝。
與代碼的問題是,你有一個錯字,應該是另有代替otherwhise更改這一部分:
$urlRouterProvider.otherwhise("/state1");
在此:
$urlRouterProvider.otherwise("/state1");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.