gpt4 book ai didi

Angularjs 错误 : [$location:nobase]

转载 作者:行者123 更新时间:2023-12-03 21:04:57 35 4
gpt4 key购买 nike

你尝试创建一个带有 Angular 的简单网络
项目 asp.net mvc 5
我有这个 js

var app = angular.module("app", ["ngRoute"])
.config(function ($routeProvider, $locationProvider) {
$routeProvider.when('/', {
templateUrl: '/AngularJS/Templates/inicio.html',
controller: 'bienvenidoController'
});
$locationProvider.html5Mode(true);
});

和这个:
app.controller("bienvenidoController", function ($scope) {

});

看法:
布局:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title - My ASP.NET Application</title>
</head>
<body ng-app="app">
@RenderBody()
<!--Librerias Angular-->
<script src="~/Scripts/angular.min.js"></script>
<script src="~/Scripts/angular-route.min.js"></script>

<!---Librerias App-->
<script src="~/AngularJS/RegistrationModule.js"></script>
<script src="~/AngularJS/bienvenidoController.js"></script>
</body>
</html>

指数:
<div ng-view>

</div>

和:
<h1>Hola Mundo!</h1>

错误:

Error: [$location:nobase]



错误参见 firebug mozilla

最佳答案

如 AngularJs 文档所述

If you configure $location to use html5Mode (history.pushState), you need to specify the base URL for the application with a tag or configure $locationProvider to not require a base tag by passing a definition object with requireBase:false to $locationProvider.html5Mode()



https://docs.angularjs.org/error/$location/nobase

您错过了 <base href="/">在您的文档中,或者您可以通过设置禁用检查
$locationProvider.html5Mode({
enabled: true,
requireBase: false
});

关于Angularjs 错误 : [$location:nobase],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32098585/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com