AngularJS ui-routing项目 - 来自https://angular-ui.github.io/ui-router/#resources
问题描述:
我想使用AngularJS ui-routing制作示例应用程序。 我在这里使用教程:https://angular-ui.github.io/ui-router/#resources 当我在Chrome中本地运行网站时,控制台中出现错误。
下面是错误:AngularJS ui-routing项目 - 来自https://angular-ui.github.io/ui-router/#resources
- 错误:未能执行 '历史记录' 'replaceState':一个历史状态 对象与URL “文件:///用户/ ****** /桌面/ui-routes-site/index.html#/index.html空 '
- 错误” 不能与原点的文档中创建':循环依赖:uiViewDirective
- 错误:循环依赖:uiSrefDirective
我不太确定该怎么做,因为我刚刚从教程中复制了这些文件。 如果以前有人看过类似的东西,或者知道Angular的循环错误,请帮忙!
什么我的代码如下所示:
//index.html
<!doctype html>
<html ng-app="myApp">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.min.js"></script>
<script src="js/angular-ui-router.min.js"></script>
<script>
var myApp = angular.module('myApp', ['ui.router']);
// For Component users, it should look like this:
// var myApp = angular.module('myApp', [require('angular-ui-router')]);
</script>
</head>
<body>
<div ui-view></div>
<a ui-sref="state1">State 1</a>
<a ui-sref="state2">State 2</a>
</body>
</html>
// js/app.js
var routerApp = angular.module('routerApp', ['ui.router']);
routerApp.config(function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/home');
$stateProvider
// HOME STATES AND NESTED VIEWS ========================================
.state('home', {
url: '/home',
templateUrl: 'partial-home.html'
})
// ABOUT PAGE AND MULTIPLE NAMED VIEWS =================================
.state('about', {
// we'll get to this in a bit
});
});
//partials/state1.html
<h1>State 1</h1>
</hr>
<a ui-sref="state1.list">Show List</a>
<div ui-view></div>
//partials/state1.list.html
<h3>List of State 1 Items</h3>
<ul>
<li ng-repeat="item in items">{{ item }}</li>
</ul>
//js/angular-ui-router.min.js
/**
* State-based routing for AngularJS
* @version v0.2.18
* @link http://angular-ui.github.com/
* @license MIT License, http://www.opensource.org/licenses/MIT
*/
/* commonjs package manager support (eg componentjs) */
if (typeof module !== "undefined" && typeof exports !== "undefined" && module.exports === exports){
module.exports = 'ui.router';
}
(function (window, angular, undefined) {
/*jshint globalstrict:true*/
/*global angular:false*/
'use strict';
var isDefined = angular.isDefined,
isFunction = angular.isFunction,
isString = angular.isString,
isObject = angular.isObject,
isArray = angular.isArray,
forEach = angular.forEach,
extend = angular.extend,
copy = angular.copy,
toJson = angular.toJson;
function inherit(parent, extra) {
return extend(new (extend(function() {}, { prototype: parent }))(), extra);
}
function merge(dst) {
forEach(arguments, function(obj) {
if (obj !== dst) {
forEach(obj, function(value, key) {
if (!dst.hasOwnProperty(key)) dst[key] = value;
});
}
});
return dst;
}
/**
* Finds the common ancestor path between two states.
*
* @param {Object} first The first state.
etc...
答
在你的app.js中,更改为
var routerApp = angular.module('myApp');