2015-08-19 13 views
11

y cercano di creare un semplice web con angolare progetto asp.net mvc 5 ho questo js

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

e questo:

app.controller("bienvenidoController", function ($scope) { 

}); 

vista: Disposizione:

<!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> 

index:

<div ng-view> 

</div> 

e:

<h1>Hola Mundo!</h1> 

errore:

Error: [$location:nobase]

errore vedere in Firebug mozilla

risposta

32

Come indicato nella documentazione 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

Ti manca il <base href="/"> nel documento oppure è possibile disabilitare il controllo impostando

$locationProvider.html5Mode({ 
    enabled: true, 
    requireBase: false 
}); 
+0

grazie, funziona –

0

Basta aggiungere <base href="/"> nella sezione <head> del documento HTML e il gioco è fatto.

<head> 
    <base href="/"> 
    ... 
</head> 

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

Problemi correlati