Javascript $locationProvider.html5Mode(true)抛出类型错误:无法读取属性';更换';在AngularJS中未定义的
尝试使用$locationProvider.html5Mode时(true)我得到“TypeError:无法读取未定义的属性'replace'。当我把它注释掉时,我没有得到错误,但是我在URL中有“#”字符,我正试图去掉这些字符。我看到有人报告说ui.router存在一些类似的问题,我没有使用这些问题。无论如何,我无法从这些帖子中找到解决方案。任何帮助都将不胜感激。谢谢 parserconfig.htmlJavascript $locationProvider.html5Mode(true)抛出类型错误:无法读取属性';更换';在AngularJS中未定义的,javascript,angularjs,html,Javascript,Angularjs,Html,尝试使用$locationProvider.html5Mode时(true)我得到“TypeError:无法读取未定义的属性'replace'。当我把它注释掉时,我没有得到错误,但是我在URL中有“#”字符,我正试图去掉这些字符。我看到有人报告说ui.router存在一些类似的问题,我没有使用这些问题。无论如何,我无法从这些帖子中找到解决方案。任何帮助都将不胜感激。谢谢 parserconfig.html <!DOCTYPE html> <html ng-app='parser
<!DOCTYPE html>
<html ng-app='parserconfigApp'>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<script src="https://code.angularjs.org/1.4.0/angular-route.min.js"></script>
<base href="file:///home/myusername/projects/parser_ui/">
<title>Parser Config</title>
</head>
<body>
<div ng-controller='ParserConfigController as parserConfig'>
<h1>Record Types</h1>
<table style="font-size: medium; width: 50%; table-layout: fixed" ng-repeat='recordType in recordTypes'>
<tr>
<td><a>{{recordType}}</a></td>
<td><button ng-click="remove($index)">Remove</button><td>
</tr>
</table>
<a href="/addRecordType">Add</a>
</div>
<div ng-view></div>
<script type="text/javascript" src="parserconfigApp.js"></script>
</body>
</html>
你能做一个plunkr/jsfiddle来演示你的问题吗?@Dan Pantry:jsfiddle能处理AngularJS1.3吗?我只看到1.2。是的。Codepen fiddle和plunkr都有选项。@Dan Pantry:我在这里设置什么?@jazzblue:
/
。它不必是一条绝对路径
'use strict';
var app = angular.module('parserconfigApp', ['ngRoute']);
app.controller('ParserConfigController', ['$scope', '$location', function($scope, $location) {
$scope.recordTypes = recordTypes;
$scope.remove = function(index) {
$scope.recordTypes.splice(index, 1);
}
$scope.changeView = function(view) {
alert($location.path())
$location.path(view);
alert($location.path())
}
}]);
app.controller('AddRecordTypeController', ['$scope', function($scope) {
}]);
app.config(function($routeProvider, $locationProvider) {
$routeProvider
.when('/addRecordType', {
templateUrl: 'partials/partial1.html',
controller: 'AddRecordTypeController'
})
.otherwise({
redirectTo: '/addRecordType'
});
// use the HTML5 History API
$locationProvider.html5Mode(true);
});
var recordTypes = [
'Boot Record',
'Card Uptime Record',
'Stack Trace'
];