0


我想使用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... 

回答

0

在你的app.js中,更改爲

var routerApp = angular.module('myApp');