-1
angularjs Route funktioniert nicht richtig. erste Seite zeige andere Seite nicht die Ansicht wechseln. hier ist der CodeWinkelroute funktioniert nicht richtig. erste Seite zeige andere Seite nicht die Ansicht wechseln
script.js
var app = angular.module("myApp", ["ngRoute"]);
app.config(function($routeProvider) {
$routeProvider
.when("/", {
templateUrl: "home.html",
})
.when("/About", {
templateUrl: "About.html",
})
.when("/contact", {
templateUrl: "contact.html",
});
});
index.html
<!DOCTYPE HTML>
<html>
<head>
<title>Welcome Home</title>
</head>
<body ng-app="myApp">
<p><a href="#">Main</a></p>
<a href="#About">About</a>
<a href="#contact">contact</a>
<h3> welcome to the page</h3>
<div ng-view></div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular-route.js"></script>
<script src="script.js"></script>
</body>
</html>
home.html
<h1>Welcome Home </h1>
about.html
<h1>Welcome About </h1>
contact.html
<h1>Welcome Contact </h1>
Gibt es einen Fehler auf der Konsole? –
hinzufügen $ locationProvider.html5Mode (true); und verwende nicht href = "# about", entferne # von href. –
fügen Sie einfach # hinzu! vor href wird es funktionieren wie "About" – Arun